, - , (, , !).
These histograms don't align or nothing here, just literally counting a pixel of a specific value in each strip.
I believe the groups (you will need to check): R, G, B + Alpha in that order.
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.io.File;
import javax.imageio.ImageIO;
public class SimpleImageReader {
public static void main(String[] args) throws Exception {
File f=new File("C:\\1.jpg");
BufferedImage img = ImageIO.read(f);
Raster r=img.getData();
int levels=256;
int bands=r.getNumBands();
int histogram[][]=new int[bands][levels];
for (int x=r.getMinX();x<r.getWidth();x++) {
for (int y=r.getMinY();y<r.getHeight();y++) {
for (int b=0;b<3;b++) {
int p=r.getSample(x, y, b);
histogram[b][p]++;
}
}
}
for (int b=0;b<histogram.length;b++) {
System.out.println("Band:"+b);
for (int i=0;i<histogram[b].length;i++) {
System.out.println("\t"+i+"="+histogram[b][i]);
}
}
}
}
source
share