The code below is an image processing routine. The x and y represent the coordinated of all of the pixels that make up the image. The basics are as follows:
- x, y - coordinates of each pixel.
- imgH, imgW - height and width in pixels of the image
- r, g, b - The red, green, and blue levels of each pixel
The code uses a double for loop to do something to each pixel in the image. What I want to do inside this for loops is for each pixel, I want to average the r,g,b values of the 8 surrounding pixels, and make that average the value of the center pixel. This will create the effect of blurring the image. Could anybody help me with this?
protected void proc_17() {
info = "";
for (int y = 0; y < imgH; y++) {
for (int x = 0; x < imgW; x++) {
int xNext = (x+1) % imgW;
int yNext = (y+1) % imgH;
float r = (imgOld.getR(xNext, yNext) + imgOld.getR(xNext, yNext)) / 8;
float g = (imgOld.getG(xNext, yNext) + imgOld.getG(xNext, yNext)) / 8;
float b = (imgOld.getB(xNext, yNext) + imgOld.getB(xNext, yNext)) / 8;
imgNew.setR(x, y, r);
imgNew.setG(x, y, g);
imgNew.setB(x, y, b);
}
}
}