我正在尝试比较灰度图像中的两个直方图。我正在使用 CV_COMP_CHISQR(0.0 完美匹配 - 1.0 完全不匹配)。我将两个直方图都归一化为 1。但是当我比较直方图时,我得到的结果超过 40.0,这是没有意义的。我不知道是否可能我错过了一些步骤或者可能有什么问题。这是代码的快照。
public class Histogram {
public static void main(String[] args) throws Exception {
String baseFilename = ".../imgs/lp.jpg";
String contrastFilename = ".../imgs/lpUrb.jpg";c/surf_javacv/box_in_scene.png";
IplImage baseImage = cvLoadImage(baseFilename);
CvHistogram hist=getHueHistogram(baseImage);
IplImage contrastImage = cvLoadImage(contrastFilename);
CvHistogram hist1=getHueHistogram(contrastImage);
double matchValue=cvCompareHist(hist, hist1, CV_COMP_CHISQR );
System.out.println(matchValue);
}
private static CvHistogram getHueHistogram(IplImage image){
if(image==null || image.nChannels()<1) new Exception("Error!");
IplImage greyImage= cvCreateImage(image.cvSize(), image.depth(), 1);
cvCvtColor(image, greyImage, CV_RGB2GRAY);
//bins and value-range
int numberOfBins=256;
float minRange= 0f;
float maxRange= 255f;
// Allocate histogram object
int dims = 1;
int[]sizes = new int[]{numberOfBins};
int histType = CV_HIST_ARRAY;
float[] minMax = new float[]{minRange, maxRange};
float[][] ranges = new float[][]{minMax};
int uniform = 1;
CvHistogram hist = cvCreateHist(dims, sizes, histType, ranges, uniform);
// Compute histogram
int accumulate = 0;
IplImage mask = null;
IplImage[] aux = new IplImage[]{greyImage};
cvCalcHist(aux,hist, accumulate, null);
cvNormalizeHist(hist, 1);
cvGetMinMaxHistValue(hist, minMax, minMax, sizes, sizes);
System.out.println("Min="+minMax[0]); //Less than 0.01
System.out.println("Max="+minMax[1]); //255
return hist;
}
}//CLass end