ZIP your submission, which should be your entire Processing sketch folder (not just the files in the folder, but the folder itself).
See each problem for its value. Liberal deductions (up to 25% of the assignment value) for code that is hard to read, poor variable names, lack of comments, and other style issues. Processing has a keyboard shortcut, Ctrl-T on Windows, Command-T on Macs, that will clean up your source code for you quite a bit. Press it. I will charge you 2 points for leaving the pressing to me).
Note that each of your filter methods should return a new PImage object, without modifying the PImage object that is passed in as an argument.
Write a PImage soften(PImage src, int strength)method that softens an image by computing the average of a pixel’s color and the colors of its neighboring pixels.
That is, to compute the new color for a pixel, average the colors of the original pixel and its neighbors (where strength determines how many neighbors).
The strength refers to the size of the neighborhood of surrounding pixels that will be included. The greater the strength, the larger the area. Intuitively, think of a square wrapped around a pixel such that the number of pixels to the right, left, top, and bottom is equal to the strength. Or, stated another way, with an example, if you use a strength of 3, then imagine a 7 by 7 grid of pixels with your pixel in the middle.
Or, stated in a fancier way, if the strength is 3, then you should be considering all pixels whose Chebyshev distance to your pixel is less than or equal to 3. Pixels at or near the border will require special attention. For example, if you are using a strength of 5, and your pixel is at row 7, column 6, then it is easy to go out 5 in each direction from the center pixel.
But if you are using a strength of 10, and your center pixel is at row 7, column 6, and you try to move left 10 (or up 6) you will go past the edge of the image. In those cases, you should still compute the average of all the available pixels whose Chebyshev distance to your pixel is less than or equal to 3
In your soften()method, use millis() to print a measure of the time it takes to soften your image. Only measure the part of the code that is doing the softening. In other words, assuming you have a loop where all the calculations are taking place, note the time just before the loop starts, and again immediately after the loop ends, and print the elapsed milliseconds.
Then, make your soften() method as efficient as possible using techniques from class. Don’t come up with a different algorithm: you still need to use the algorithm exactly as described above (averaging the colors of surrounding pixels), but find ways to tweak your code so that the algorithm performs as quickly as possible. (I will, in a sense, grade on a curve, with the most efficient solutions earning the most points. I will test your code on my own images.)
Write aPImage scramble(PImage src, int xDivs, int yDivs) method that breaks an image up into rectangles, and then shuffles those rectangles randomly. xDivs determines the number of horizontal divisions, and yDivs determines the number of vertical divisions. So, for example, scramble(src, 4, 3) would result in a grid of 12 rectangles (4 columns, 3 rows), and then those rectangles would be scrambled.
Note that xDivs must divide evenly into the width of the image, and yDivs must divide evenly into the height of the image. Throw a helpful illegalArgumentException() if xDivs or yDivs is not a good value. This would be an appropriate exception:
IllegalArgumentException: yDivs 7 is not a divisor of the height 300
Write a method PImage bestMatch(PImage src, color[] palette)that returns a new PImage where each pixel in the new image is the color in palette that most closely matches the corresponding pixel in src.
In other words, imagine you are trying to make a copy of src, but you are limited only to the colors in palette (like, if you were given a box of crayons, and told to use them to reproduce the image). Find the best matching color in the palette for each pixel. There are many definitions of “best matching color”, but we will use a straightforward approach: For a given pixel p, compute the Euclidean distance between the R,G,B values of p and the R,G,B values of each color in palette.
Use the color in palette with the minimum Euclidean distance from p. Note that Processing has a dist() method that can compute the distance between two 3D points. An R,G,B color can be thought of as a 3D point, because it has 3 components.
Create a color[] randomPalette(int n)method that creates and returns an array of n random colors. Modify your bestMatch() method to use the randomPalette() method so that it is easy for your instructor to try various sizes of palettes.
Write a PImage rotate(PImage src, float angle)method that rotates an image a specified number of degrees, about the center of the image. Note that this will result in an image where some pixels will not have part of the image in it.
Make upat least one additional filter of your own. Like the other filters, it should take a PImage source, and return a new PImage object, without modifying the original image. The goal here is originality. Don’t take an existing filter algorithm and make modifications to it. Rather, start from scratch to create a filter of your own.
Organize all your work by loading an image and showing a gallery of your results (in rows and columns). For thesoften() method, call it with several strengths, so that the results can be compared. So, when you run your program, the user should see a bunch of different versions of the loaded image (along with the time it took for each soften operation).