Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given this code: Write a Java program that applies one a among the above filters

ID: 642399 • Letter: G

Question

Given this code:

Write a Java program that applies one a among the above filters sequentially to a multiple Jpeg files. The main function must be in a class called MyProcessor. The program should take the filter name and a directory name on its command line (it's very close to the example program above, but just a bit more general). For instance, the command:

should apply the smear filter to all Jpeg files named "image_*.jpg" in the ".images/" directory. The possible filter names are: oil6, oil1, invert, or smear.

For each input file, say image.jpg, the program should create a new file called filter_image.jpg where filter is the filter name in the same directory as that of the input file.

Your program should print 'r' after reading an image, 'p' after processing an image, and 'w' after writing an image. Here is an example command-line interaction with the program:

** PLEASE LET ME KNOW IF YOU HAVE QUESTIONS OR NEED CLARIFICATIONS :D **

Explanation / Answer

i used oil filter

import java.awt.*;

public class OilFilter extends WholeImageFilter {

private int range = 3;
private int levels = 256;

public OilFilter() {
}
public void setRange( int range ) {
this.range = range;
}


public int getRange() {
return range;
}

public void setLevels( int levels ) {
this.levels = levels;
}


public int getLevels() {
return levels;
}

protected int[] filterPixels( int width, int height, int[] inPixels, Rectangle transformedSpace ) {
int index = 0;
int[] rHistogram = new int[levels];
int[] gHistogram = new int[levels];
int[] bHistogram = new int[levels];
int[] rTotal = new int[levels];
int[] gTotal = new int[levels];
int[] bTotal = new int[levels];
int[] outPixels = new int[width * height];

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
for (int i = 0; i < levels; i++)
rHistogram[i] = gHistogram[i] = bHistogram[i] = rTotal[i] = gTotal[i] = bTotal[i] = 0;

for (int row = -range; row <= range; row++) {
int iy = y+row;
int ioffset;
if (0 <= iy && iy < height) {
ioffset = iy*width;
for (int col = -range; col <= range; col++) {
int ix = x+col;
if (0 <= ix && ix < width) {
int rgb = inPixels[ioffset+ix];
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = rgb & 0xff;
int ri = r*levels/256;
int gi = g*levels/256;
int bi = b*levels/256;
rTotal[ri] += r;
gTotal[gi] += g;
bTotal[bi] += b;
rHistogram[ri]++;
gHistogram[gi]++;
bHistogram[bi]++;
}
}
}
}

int r = 0, g = 0, b = 0;
for (int i = 1; i < levels; i++) {
if (rHistogram[i] > rHistogram[r])
r = i;
if (gHistogram[i] > gHistogram[g])
g = i;
if (bHistogram[i] > bHistogram[b])
b = i;
}
r = rTotal[r] / rHistogram[r];
g = gTotal[g] / gHistogram[g];
b = bTotal[b] / bHistogram[b];
outPixels[index] = (inPixels[index] & 0xff000000) | ( r << 16 ) | ( g << 8 ) | b;
index++;
}
}
return outPixels;
}

public String toString() {
return "Stylize/Oil...";
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote