Lab 1: Mean Image Median
Overview
In this assignment, you will read images in the plain PPM format and produce an image that contains the median and average of the input images.
Video introduction for the lab
Pre-Lab (DUE BEFORE LAB - see due date in Canvas)
As part of the pre-lab activity you will see how to use GitHub Classroom to start your lab assignment and submit it when you are finished. When watching the video below, consider the following.
- How to start a new project from your GitHub repository
- How to commit changes to your local repo
- How to push changes from your local repo to GitHub
- Watch [5:24] [link]
The project is cloned from the GitHub repo to your local machine at the three minute mark in the video. You will likely need to authorize IntelliJ to access your GitHub account. Hopefully the process is simple enough, but you can see screenshots for what to do in Figures 13-16 of this page.
What Must Be Done by the Pre-lab Due Date?
- Ensure you have a GitHub account
- Accept your instructor's invitation to the lab 1 assignment in Canvas
- Associate your GitHub account with your name in GitHub Classroom
- Clone the project, openning it in IntelliJ
- Rename the
username
package to your username - Commit the changes
Assignment
Your program must accept the following input information:
- Operation preference — either
median
ormean
(all lowercase) - Output filename — e.g.,
images/output.ppm
- At least two input image filenames — e.g.,
images/input1.ppm
andimages/input2.ppm
Note that all input files must have the same dimensions.
Your program may use command line arguments or console input to obtain the input information. The program must produce an output image that, at each location in the image, contains either the median or average of the (red, green, and blue) components of all of the input pixels at that location.
Details
mocked
Package
You are provided with a mocked.Image
class implementation containing the following methods:
int getWidth()
— returns the width of the image.int getHeight()
— returns the height of the image.mocked.PixelReader getPixelReader()
— returns an object that implements thePixelReader
interface.
You are also provided with a mocked.WritableImage
class implementation which
extends mocked.Image
and contains:
WritableImage(int width, int height)
— creates a writable image of the specified size.mocked.PixelWriter getPixelWriter()
— returns an object that implements thePixelWriter
interface.
The mocked.PixelReader
interface provides one method: int getArgb(int x, int y)
which
returns the 32-bit integer value of the color of the pixel located at x, y.
The mocked.PixelWriter
interface provides one method: int setArgb(int x, int y, int argb)
which sets the 32-bit integer value of the color of the pixel located at x, y.
Lab1
Class
You must also implement the Lab1
class that will contain your main program.
void main(String[] args)
— Entry point for your program
MeanImageMedian
Class
You must implement the MeanImageMedian
class that will contain several methods to be called by your program to complete the requirements of the assignment. Your class must have the
following public
class methods:
Image readPPMImage(Path imagePath)
— Reads the.ppm
image file specified by the image path. Consult Javadoc in starter code for details.void writePPMImage(Path imagePath, Image image)
— Writes image to a.ppm
image file specified by the image path. Consult Javadoc in starter code for details.Image calculateMedianImage(Image[] inputImages)
— calculates the median color for each pixel in the input images. Consult Javadoc in starter code for details.Image calculateMeanImage(Image[] inputImages)
— calculates the mean color for each pixel in the input images. Consult Javadoc in starter code for details.
Several private helper methods are provided in the MeanImageMedian
class to
help you work with ARGB (alpha, red, green, and blue) values. You are encouraged
to identify and implement additional private methods in the MeanImageMedian
class.
Plain PPM Format
Your program must support the plain PPM format for 24-bit color images. Each pixel in the image is represented by an 8-bit integer value (between 0 and 255).
The contents of a PPM file representing an image the is two pixels wide and three pixels tall is shown below:
P3
2 3
255
255 255 255 255 255 255
0 0 0 255 0 0
0 255 0 0 0 255
- The first line must begin with P3 followed by whitespace (typically a new line)
- An integer specifying the width is next, followed by whitespace
- An integer specifying the height is next, followed by whitespace
- An integer specifying the MAXVALUE is next (for this lab, the value must be 255), followed by whitespace
- The remainder of the file specifies the pixel values (left to right, from top to bottom), separated by whitespace
- Each pixel is specified with three integer values between 0 and 255, separated by whitespace
- The first integer specifies the intensity of Red
- The second integer specifies the intensity of Green
- The third integer specifies the intensity of Blue
- Since the PPM format does not support transparency of the pixels, the Alpha value should always be set to 255.
Exception Handling
If any problems are encountered with reading the input files or writing the output file, the program should display a useful error message to the console and terminate gracefully. The program should not crash or display any exceptions.
Just For Fun
Ambitious students may wish to:
- Read and write more common image formats.
Acknowledgement
This laboratory assignment, developed by Dr. Chris Taylor.