I have to implement the median filter. I found an example on the internet but it does not run, I do not see the image, where am I wrong?
Thankspublic void median_RGB(Immagine img) { int maskSize = 3; int width = img.getW(); int height = img.getH(); int outputPixels[] = new int[width * height]; int red[], green[], blue[]; int xMin, xMax, yMin, yMax; int argb, reD, greenN, bluE; /** Median Filter operation */ for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int a = img.getAlpha(x, y); red = new int[maskSize * maskSize]; green = new int[maskSize * maskSize]; blue = new int[maskSize * maskSize]; int count = 0; xMin = x - (maskSize / 2); xMax = x + (maskSize / 2); yMin = y - (maskSize / 2); yMax = y + (maskSize / 2); for (int r = yMin; r <= yMax; r++) { for (int c = xMin; c <= xMax; c++) { if (r < 0 || r >= height || c < 0 || c >= width) { /** Some portion of the mask is outside the image. */ continue; } else { argb = img.getOriginalImage().getRGB(c, r); reD = (argb >> 16) & 0xff; red[count] = reD; greenN = (argb >> 8) & 0xff; green[count] = greenN; bluE = (argb) & 0xFF; blue[count] = bluE; count++; } } } /** sort red, green, blue array */ java.util.Arrays.sort(red); java.util.Arrays.sort(green); java.util.Arrays.sort(blue); /** save median value in outputPixels array */ int index = (count % 2 == 0) ? count / 2 - 1 : count / 2; logger.info("valore mediano " + index); int p = (a << 24) | (red[index] << 16) | (green[index] << 8) | blue[index]; outputPixels[x + y * width] = p; } } /** Write the output pixels to the image pixels */ for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { img.getOriginalImage().setRGB(x, y, outputPixels[x + y * width]); } } }