我需要确定图像中颜色的数量/质量,以便将其与其他图像进行比较,并推荐用户(图像的所有者),也许他需要将其打印成黑白而不是彩色。 / p>
到目前为止,我正在分析图像并提取它的一些数据:
为了进一步分析,我可能需要这些图像的其他特征。你知道图像分析中还有什么重要的(或者我在这里缺少)吗?
答案 0 :(得分:0)
过了一段时间后,我发现了一个缺失的特征(非常重要),这对我的图像分析有很大帮助。我不知道是否有名称,但我称之为图像的平均颜色:
当我循环遍历图像的所有像素并计算每种颜色时,我还检索了RGB值的信息,并总结了所有像素的所有红色,绿色和蓝色。只是想出这种平均颜色,当我想比较某种图像时再次挽救了我的生命。
代码是这样的:
File f = new File("image.jpg");
BufferedImage im = ImageIO.read(f);
int tot = 0;
int red = 0;
int blue= 0;
int green = 0;
int w = im.getWidth();
int h = im.getHeight();
// Going over all the pixels
for (int i=0;i<w;i++){
for (int j=0;j<h;j++){
int pix = im.getRGB(i, j); //
if (!sameARGB(pix)) { // Compares the RGB values
tot+=1;
red+=pix.getRed();
green+=pix.getGreen();
blue+=pix.getBlue();
}
}
}
你应该得到这样的结果:
// Percentage of color on the image
double per = (double)tot/(h*w);
// Average color <-------------
Color c = new Color((double)red/tot,(double)green/tot,(double)blue/tot);