2016-06-28 18 views
0

いくつかの同等基準のために2つの画像ファイルを比較したいと思います。2つの画像の画像比較

2つのイメージファイルを何パーセントまで比較できるツールはありますか? 2つの画像を渡すと、画像が約xで一致することがわかるはずです。

+0

JavaまたはJavaScriptを使用していますか? – Timo

+0

私は両方のスコープを持っています。私はそれをクライアントサイド、すなわちjavaスクリプトまたはサーバサイドのいずれかで処理するオプションを持っています。 – sunder

+0

[この図書館はあなたが尋ねることを行います:https://huddle.github.io/Resemble.js/](https://huddle.github.io/Resemble.js/) –

答えて

2

これは正確にはお望みではないかもしれませんが、実際には画像の操作と分析のコードを書くことができますかなり便利です。これはJavaにあります。

//Image percentage match 
public float getPercentMatch(String imageFile1, String imageFile2) { 

//Set how close a pixel has to be for a match, pixel deviation 
int pd = 3; 

    try { 
    //get height, width and image from first file 
    File input1 = new File(imageFile1); 
    image1 = ImageIO.read(input1); 
    width1 = image1.getWidth(); 
    height1 = image1.getHeight(); 

    //Do the same for the second one 
    File input2 = new File(imageFile2); 
    image2 = ImageIO.read(input2); 
    width2 = image2.getWidth(); 
    height2 = image2.getHeight(); 

    int matchCount = 0; 

    //Make sure they're the same height. You could also choose to use the 
    //smaller picture for dimensions 
    if (height1 != height2 || width1 != width2) {return 0.0;} 


    //Iterate over each pixel 
    for(int i=0; i<height1; i++){ 

     for(int j=0; j<width1; j++){ 

      //Get RGB values for each image at certain pixel 
      Color c1 = new Color(image1.getRGB(j, i)); 
      Color c2 = new Color(image2.getRGB(j, i)); 

      // If the colors are close enough based on deviation value... 
      if ( (Math.abs(c1.getRed() - c2.getRed()) < pd) && 
        (Math.abs(c1.getGreen() - c2.getGreen()) < pd) && 
        (Math.abs(c1.getBlue() - c2.getBlue()) < pd)) { 
       //...it's a match, so increment the match count 
       matchCount++; 
      } 
     } 
    } 
    return matchCount/(height1 * width1); 

    } catch (Exception e) {} 
}