To gain experience with storing data in Java programs including using classes, multi-dimensional arrays, and program parameters.
For this program, you will write a program that converts images from full color into greyscale.
Most image file formats write the image data in binary, and utilize compression in order to keep the file sizes small. Unfortunately, this makes reading them in quite difficult. In contrast, the PPM image format is textual and quite simple and easy to work with.
A PPM image file contains the following:
To convert an image to greyscale, you can simply average the red, green and blue values for a given pixel, then write that value over the red, green and blue values.
For example, if a pixel has a red value of 250, a green value of 100, and a blue value of 10, it will be a bright orange color. If we wish to convert the color to greyscale, we average 250, 100 and 10 which gives us 120. If we set the red, green and blue values all to 120, we get a grey color roughly as bright as the orange.
If we apply this process to each of the pixels in the image, it will be greyscale.
Input Image | PNG Version | Expected Output | PNG Version |
eagle.ppm | eagle.png | eagle-grey.ppm | eagle-grey.png |
farmer.ppm | farmer.png | farmer-grey.ppm | farmer-grey.png |
snow.ppm | snow.png | snow-grey.ppm | snow-grey.png |
In order to test your program's output, you will need to view the images. Image viewers on Linux and Mac usually support PPM images natively. So if you are using one of these systems, you should be able to just open the image file like usual.
On Windows, this is usually not the case. You can use the image viewer IrfanView which is free and supports many image formats, including PPM. With this installed, you should be able to see your generated PPM images and make sure they look right.
For extra credit, you can perform any other kind of image manipulation effect you wish. Examples might include flipping the image, lightening, darkening, applying Instagram-like filters etc. If you complete an extra credit effect, you should write the modified image to a file called "extra.ppm". You also must briefly describe the effect a comment along with your submission.
When you are finished, please upload your code to the Canvas page for this assignment. Please send the .java file(s) only.
Copyright © 2024 Ian Finlayson | Licensed under a Creative Commons BY-NC-SA 4.0 License.