2012-02-03 114 views
1

我需要确定图像中的颜色数量/质量,以便与其他图像进行比较,并推荐用户(图像的所有者),可能需要用黑白色打印它并不是颜色。从图像中检索颜色信息

到目前为止,我分析图像,提取它的一些数据:

  • 我像
  • 颜色在整个页面的百分比找到(彩色像素的不同颜色的数量/总像素)

为了进一步分析,我可能需要这些图像的其他特征。你知道在图像分析中还有哪些重要的东西(或者我在这里失踪)?

回答

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);