get Intensity Sub matrix from BufferedImage - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage

Description

get Intensity Sub matrix from BufferedImage

Demo Code


import java.awt.Color;
import java.awt.image.BufferedImage;

public class Main{
    private static int getIntensitySubmatrix(int x, int y, int scale,
            BufferedImage image) {
        int intensity = 0;
        for (int i = x; i < x + scale; i++) {
            for (int j = y; j < y + scale; j++) {
                intensity += RenderUtils.intensity(i, j, image);
            }//w  w w .  jav a  2 s  .c  o m
        }
        return intensity / (scale * scale);

    }
    private static int intensity(int x, int y, BufferedImage image) {
        Color col = new Color(image.getRGB(y, x), false);
        int red = col.getRed();
        int blue = col.getBlue();
        int green = col.getGreen();
        int intensity = (red + blue + green) / 3;
        return intensity;
    }
}

Related Tutorials