Lab 2: Mean Image Median Displayed
In this assignment, you will incorporate lab 1 feedback from your instructor (if available), and load and display images in a graphical user interface.
Pre-Lab (DUE BEFORE LAB - see due date in Canvas)
As part of the pre-lab activity you must ensure that you have JavaFX installed on your laptop.
In addition to incorporating feedback from your instructor, you must replace
the code in the
mocked package with appropriate JavaFX code (change the imports to
javafx.scene.image classes). You must:
- Ensure that alpha value is set to 255 in
writeImage()methods with the same parameters as
writePPMImage()that will call
writePPMImage()when the file extention on the
calculateMeanImage()calculate alpha value for each pixel.
- Create a
Lab2class that extends the JavaFX
Applicationclass and overrides the
start()method. (Leave the
Lab1class, but it will not be used in this application.)
writeImage()methods to use JavaFX classes to add support for reading and writing JPG and PNG file formats.
- If a path with an unsupported file extension is passed to either
writeImage(), the method should throw an
- Ensure that the
Lab2class catches any exceptions thrown and displays a useful error message before exiting gracefully.
javax.imageio.ImageIO.write() method, and you can use the
javafx.embed.swing.SwingFXUtils.fromFXImage() method to
BufferedImage (that is a
If writing PNG files works but it doesn't work for JPG files, don't worry
Your program must run as a
.jar file from the command line and accept the
- Operation preference — either
- Output filename — e.g.,
- At least two input image filenames — e.g.,
Potentially useful tutorials:
.jar file is created, move it from the
folder into the project folder (same folder as the README.md file) and rename
The program will process the input images to produce the desired output and then save and display the resulting image. For example,
java -jar lab2.jar median images/codeMedian.ppm images/code1.png images/code2.png images/code3.png
codeMedian.ppm in the
images folder that is the median of the first three
Image in the
by placing the
Image in a
that is placed in an
HBox that then gets added
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:
- Display all of the input images as well as the output image.
This laboratory assignment, developed by Dr. Chris Taylor.