Question: Java GrayScale1Filter.java & GrayScale2Filter.java implement Filter.java I don't know where to start, the code must include public void filter(PixelImage theImage) { // get the data

Java GrayScale1Filter.java & GrayScale2Filter.java implement Filter.java

I don't know where to start, the code must include

public void filter(PixelImage theImage) { // get the data from the image Pixel[][] data = theImage.getData();

in order to edit the images. Any help would be nice, I put what I have so far down below, but I don't think it's correct. I took some given code and changed it around which probably isn't right. The directions state to directly modify the array of pixels and I don't understand that.

Gray Scale

The second simple transform is to convert the picture to gray scale. That means that all three color components (red, green, and blue) shall have the same value after the filter is applied. Let's call this value the gray value.

The standard gray scale algorithm sets the gray value to the sum of 30% of the red value, 59% of the green value, and 11% of the blue value. We will call this Gray Scale 1.

A commonly used approximation sets the gray value to 11/32 of the red value, 16/32 of the green value, and 5/32 of the blue value. This calculation is used because it is easy to implement using integer arithmetic. We will call this Gray Scale 2.

gray = (11 * red + 16 * green + 5 * blue) / 32

Both of these transforms can be implemented by directly modifying the array of pixels.

Gray Scale 1 (using 30%, 59%, 11%)

becomes

Gray Scale 2 (using 11/32, 16/32, 5/32)

becomes

Starting Point Code (Pixel.java) can be edited into GrayScale1Filter.java and GrayScale2Filter.java

public class GrayScale1Filter implements Filter { public void filter(PixelImage theImage) { // get the data from the image Pixel[][] data = theImage.getData();

public static final int RED = 0, GREEN = 1, BLUE = 2; // RGB color values for this pixel (0-255) public int[] rgb; /** * Constructor for objects of class Pixel * Initializes the pixel values; * @param red value for red portion of pixel * @param green value for green portion of pixel * @param blue value for blue portion of pixel * @throws IllegalArgumentException if any of the parameters * are not within the bounds of 0 - 255 */ public Pixel(int red, int green, int blue) { if ((red < 0 || red > 255) || (green < 0 || green > 255) || (blue < 0 || blue > 255)) { throw new IllegalArgumentException("bad RGB value for Pixel"); } rgb = new int[3]; rgb[RED] = red; rgb[GREEN] = green; rgb[BLUE] = blue; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!