So this method I wrote gets the mean and standard deviation of an image. I am trying to modify this to get the mean and standard deviation of the red, green and blue values of an image. But I am stumped on how to do to so. I tried to use a colorModel but I was getting nowhere. Could anyone give me some advice on how to modify this code to get the mean and standard deviation of the red, green and blue values?
public static double redValues(BufferedImage image){
Raster raster = image.getRaster();
double mean = meanValue(image);
double sumOfDiff = 0.0;
Color c = new Color(image.getRGB(0, 0));
int red = c.getRed();
for (int y = 0; y < image.getHeight(); ++y){
for (int x = 0; x < image.getWidth(); ++x){
double r = raster.getSample(x, y, red) - mean;
sumOfDiff += Math.pow(r, 2);
}
}
return sumOfDiff / ((image.getWidth() * image.getHeight()) - 1);
}
But this still returns a mean brightness value. When I want to get the red value.