For this assignment, you will write several methods for manipulating JPG images. A framework for manipulating images is given to you with the following classes:
BufferedImage, that represents a JPG image and provides methods for accessing individual pixels.
ImageViewer class has methods for reducing and expanding the size of the image, for inverting all of the pixels, and for reflecting along the horizontal axis. You are to add methods to perform the following transformations:
vertical: this method reflects the image along the vertical axis, leaving the image dimensions unchanged.
grayscale: this method converts the image to grayscale. This is accomplished by setting each pixel in the image to have an RGB of the form (avg,avg,avg), where avg is the average of the existing red, green, and blue values for that pixel. For example, if a pixel had an RGB value of (100,110,150), it would be assigned the new RGB value of (120,120,120) in the grayscale version. Note that this transformation is not reversible.
filter: this method uses a greedy approach to filter the pixels based on their average neighbor difference. In general, the difference between two pixels is defined to be the sum of the differences between the RGB values of the two pixels. For example, pixels (100, 110, 150) and (120, 90, 100) would have a difference of 20+20+50=90. The average of the differences between a pixel and all of its neighbors is the average neighbor difference for that pixel. The filter method should leave the top half of all non-white pixels (i.e., those with highest average neighbor values) untouched, while all other pixels are set to white. Since the most extreme pixels remain, repeated applications of this filter perform a type of edge detection. For example, the sequence below shows how the image on the left is transformed by one and two applications of the greedy filter.