簡體   English   中英

如何比較並找出兩個直方圖是否相同?

[英]How can I compare and find if two histograms are the same?

我正在嘗試比較並檢查兩個圖像是否相互匹配。 我在android studio中找不到與OpenCV java比較的正確教程。 所以,我找到了一些步驟並開始計算直方圖,這樣我就可以比較兩個圖像的直方圖,看看它們是否匹配。

我編寫了以下方法來計算直方圖然后進行比較。

Mat matB2 = new Mat(sourceSize, sourceMat.type());
                Mat matG2 = new Mat(sourceSize, sourceMat.type());
                Mat matR2 = new Mat(sourceSize, sourceMat.type());

                    Imgproc.calcHist(channels2, allChannel2[0], new Mat(),  matB2, hisSize2, histRange2);
                    Imgproc.calcHist(channels2, allChannel2[1], new Mat(), matG2, hisSize2, histRange2);
                    Imgproc.calcHist(channels2, allChannel2[2], new Mat(), matR2, hisSize2, histRange2);

                    Toast.makeText(MainActivity.this, "test", Toast.LENGTH_SHORT).show();

                    int graphHeight2 = 300;
                    int graphWidth2 = 200;
                    int binWidth2 = 3;

                    Mat graphMat2 = new Mat(graphHeight2, graphWidth2, CvType.CV_8UC3, new Scalar(0, 0, 0));

                    //Normalize channel
                    Core.normalize(matB2, matB2, graphMat2.height(), 0, Core.NORM_INF);
                    Core.normalize(matG2, matG2, graphMat2.height(), 0, Core.NORM_INF);
                    Core.normalize(matR2, matR2, graphMat2.height(), 0, Core.NORM_INF);



  //Comparing histograms
                    int compareMethod = 1;
                    double comparisonValueB = Imgproc.compareHist(matB,matB2, Imgproc.CV_COMP_CORREL);
                    double comparisonValueG = Imgproc.compareHist(matG,matG2,Imgproc.CV_COMP_CORREL);
                    double comparisonValueR = Imgproc.compareHist(matR,matR2,Imgproc.CV_COMP_CORREL);

                    Toast.makeText(MainActivity.this, "comparisonValueB::"+comparisonValueB, Toast.LENGTH_SHORT).show();
                    Toast.makeText(MainActivity.this, "comparisonValueG::"+comparisonValueG, Toast.LENGTH_SHORT).show();
                    Toast.makeText(MainActivity.this, "comparisonValueR::"+comparisonValueR, Toast.LENGTH_SHORT).show();

然而,我通過比較值添加的三個吐司得到的結果是,

  • ** comparisonValueB:** 1984.5519 ** comparisonValueG:** 2159.2307 ** comparisonValueR:** 3420.9038

我不明白這些價值意味着什么。 有人能讓我知道這些價值意味着什么,以及如何判斷圖像是否相似。 也不是假設值介於0和1之間,其中1是最高匹配,零是最低匹配?

我是OpenCV的新手,所以請幫幫我。 如果我比較錯誤,請告訴我一個正確的方法。

首先你的問題是數字意味着什么。 你首先找到直方圖。 然后將其標准化。 然后比較兩個標准化直方圖的差異。 見下圖。 沒有標准化,它表示強度級別的像素總數。 通過歸一化,它是在一個顏色級別找到特定像素的概率。 所以你要做的是比較兩個PDF的總差異。

在此輸入圖像描述

秒如果您的任務是比較並檢查兩個圖像是否相互匹配。 然后比較直方圖可能是最差的選項見下面的例子。 如果他們的直方圖在A和B之間是相同的,那么你的想法是2圖像相同。但是我可以告訴你它現在與從瓶子看到的相同。 在底部,2個直方圖是相同的,但圖像代表不同的東西。

在此輸入圖像描述

檢查兩個圖像是否相同的簡單方法是進行模板匹配。 您可以在下面的鏈接中找到相同的代碼

https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html

> void matchTemplate(InputArray image, InputArray templ, OutputArray
> result, int method)

在此輸入圖像描述 在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM