Blur Sharpen 0 1 0 0 -1 0 1 5 1 -1 5 -1 0 1 0 0 -1 0The **Apply** button applies the filter kernel to the image. At a minimum, the button need only apply the filter kernel if the sum of the filter kernel weights is a positive value. For example, if the user enters 0 for all the filter weights, applying the filter can produce unpredictable results. The weights in the array specifying the filter kernel should sum to 1. Since the blur filter kernel has values that sum to 9 (0+1+0+1+5+1+0+1+0), each value must be divided by 9. The following code applies the **Blur** filter kernel: ``` double[] kernel = { 0.0, 1.0/9, 0.0, 1.0/9, 5.0/9, 1.0/9, 0.0, 1.0/9, 0.0}; Image blurredImage = ImageUtil.convolve(originalImage, kernel); ``` The values for filter kernel for **Sharpen** sum to 1 (5-1-1-1-1) so the weights in the array here would be: ``` double[] kernel = { 0.0, -1.0, 0.0, -1.0, 5.0, -1.0, 0.0, -1.0, 0.0}; ``` If the **Apply** button is pressed when an unsupported set of weights are entered in the window, an exception should be thrown (and be handled in a way consistent with the exception handling requirements listed below). ### Loading and Saving Images Your program must now support loading and saving `.bmsoe` files. Add the following two methods to your `ImageIO` class and modify your **`read()`** and `write()` methods to make use of these new methods when appropriate: * **`readBMSOE(Path path)`** — Reads an image file in `.bmsoe` format. * **`writeBMSOE(Image image, Path path)`** — Writes an image file in `.bmsoe` format. ### `.bmsoe` Binary Image Format The custom `.bmsoe` file format is a binary based file format for storing images. It is designed to be easy to load and save as well as produce smaller file sizes than the `.msoe` format. The file consists of a stream of binary data with the following header information: * The characters `B`, `M`, `S`, `O`, `E` each written as a `byte`. * The image width written as an `int` * The image height written as an `int` The remainder of the file contains the pixel data. Each pixel is stored as a single integer value with bits 24-31 representing the alpha channel, bits 16-23 representing the red channel, bits 8-15 representing the green channel, and 0-7 representing the blue channel. You may wish to add these two methods to your `ImageIO` class to facilitate converstion between `Color` and `int`: ``` private static Color intToColor(int color) { double red = ((color >> 16) & 0x000000FF)/255.0; double green = ((color >> 8) & 0x000000FF)/255.0; double blue = (color & 0x000000FF)/255.0; double alpha = ((color >> 24) & 0x000000FF)/255.0; return new Color(red, green, blue, alpha); } private static int colorToInt(Color color) { int red = ((int)(color.getRed()*255)) & 0x000000FF; int green = ((int)(color.getGreen()*255)) & 0x000000FF; int blue = ((int)(color.getBlue()*255)) & 0x000000FF; int alpha = ((int)(color.getOpacity()*255)) & 0x000000FF; return (alpha << 24) + (red << 16) + (green << 8) + blue; } ``` Your program should be able to load [this `.bmsoe` image](specs.bmsoe). #### Alpha Channel Complexities You may find that some images appear all black when saved in the `.bmsoe` format. This occurs when the original image does not have alpha channel information. In that case, the saved images will have values of 0 for all of the alpha channel values. You do not need to support saving such images. ### Exception Handling There are a number of situations that could cause your program to throw an exception. For example, if the file is not found, cannot be opened, or contains incorrectly formatted data, it is likely that an exception will be thrown. In these cases, the program should display an useful message and recover gracefully. ## Just For Fun There are many additional enhancements that could build on the required functionality. You are encouraged to enhance this application using your creativity. A number of enhancements are included below; however, you should not feel limited to these suggestions. * Add a menu to the main window to replace (or in addition to) the buttons * Apply a transform to only a selected region of the image * Support saving `.bmsoe` images when the input image does not have alpha channel values. * Display the original and transformed images side-by-side * Toggle between original and transformed images when mouse button is pressed on the image * Create a meme generator by adding styled text on the image * Tonal adjustment (e.g., adding a red hue to the image underneath the mouse) * Provide undo functionality * Implement additional transformations, e.g. * Brighten * Darken * Decrease color saturation * Increase color saturation * Apply additional filters like the **Edge** filter [see here](http://lodev.org/cgtutor/filtering.html) ## Lab Deliverables > See your professor's instructions for details on submission guidelines and due dates. > * Dr. Taylor's students: See below > * All other students should refer to Blackboard > >If you have any questions, consult your instructor. ## Acknowledgment This laboratory assignment was developed by [Dr. Chris Taylor](/taylor/).
2) This is a slight simplification from the actual transformation. You may chose to implement the actual transformation, if you choose to (you'll need to look it up). Be sure to indicate with a comment if you choose to do this.
3) You may choose to make a 5 x 5, 7 x 7, or 9 x 9 grid instead.