Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Vita Wiebe
- * @version PA1
- */
- public class Gaussian implements Filter
- {
- /**
- * Replace the image with a blurred version.
- *
- * @param theImage The image to modify
- */
- public void filter(PixelImage theImage) {
- // get the data from the image
- Pixel[][] data = theImage.getData();
- // for each row....
- for (int row = 0; row < theImage.getHeight(); row++) {
- // for each column in said row, replace pixels with gray version
- for (int col = 0; col < theImage.getWidth(); col++) {
- // each pixel px in data[row][col] gets an RGB array[3] corresponding to colors
- int[] px = data[row][col].rgb;
- int red = px[Pixel.RED];
- int green = px[Pixel.GREEN];
- int blue = px[Pixel.BLUE];
- // Initialize temp accumulators to calc new RGB values
- int newRed = 0;
- int newGreen = 0;
- int newBlue = 0;
- Pixel tempLast = data[row][col];
- // Iterate thru a 3x3 matrix of pixels
- for (int i = 1; i < 10; i++) {
- if (i != 5) {
- // new<color> is new color value for new pixel multiplied by weight.
- newRed += data[row][col].rgb[0] * i;
- newRed += tempLast.rgb[0];
- // greenScale += data[row][col].rgb[1];
- newGreen += data[row][col].rgb[1] * i;
- newGreen += tempLast.rgb[1];
- // blueScale += data[row][col].rgb[2];
- newBlue += data[row][col].rgb[2] * i;
- newBlue += tempLast.rgb[2];
- data[row][col] =
- new Pixel(newRed/45, newGreen/45, newBlue/45);
- }
- }
- }
- theImage.setData(data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement