for (int y = 2; y < height - 2; y++) { for (int x = 2; x < width - 2; x++) { float red = 0, green = 0, blue = 0;
// Apply the kernel to each pixel and its neighbors
for (int ky = -2; ky <= 2; ky++) { for (int kx = -2; kx <= 2; kx++) { int pixelColor = image.getRGB(x + kx, y + ky); Color color = new Color(pixelColor);
red += kernel[ky + 2][kx + 2] * color.getRed();
green += kernel[ky + 2][kx + 2] * color.getGreen(); blue += kernel[ky + 2][kx + 2] * color.getBlue(); } }
// Clamp the values to be within the valid range [0, 255]
int newRed = Math.min(255, Math.max(0, (int) red)); int newGreen = Math.min(255, Math.max(0, (int) green)); int newBlue = Math.min(255, Math.max(0, (int) blue));
// Set the new pixel color in the output image
Color newColor = new Color(newRed, newGreen, newBlue); outputImage.setRGB(x, y, newColor.getRGB()); } }
Cross-Cultural Philosophy of Traditions and Cultures Makarand R Paranjape Making India - Colonialism, National Culture, and The Afterlife of Indian English Authority