2012-02-03 130 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);