compareHist is returning very low value incase of Bhattacharyya method

asked 2017-10-05 04:20:14 -0600

reza5630 gravatar image

updated 2017-10-05 05:08:48 -0600

berak gravatar image

hello,

I have come to a problem comparing two .png images using compareHist. I have used Bhattacharyya, (method 3). but it is returning value close to 0.64. Can anyone help me with the reason and possible solution to make it work??

i have attached here two images here. thanx :)

src image search image

Code

int main(){
src_base = imread("images/src.jpg",-1);
src_test1 = imread("images/test.png",-1);
double base_test1 = hsvToHist(src_base, src_test1,3);
cout<< " Bhattacharyya template  Base-Test(1) : "<< base_test1<<endl;

return 0;  
}


double hsvToHist( Mat src_base, Mat  src_test1, int method){

Mat hsv_base, hsv_test1;
cvtColor( src_base, hsv_base, COLOR_BGR2HSV );
cvtColor( src_test1, hsv_test1, COLOR_BGR2HSV );

/// initialization to calculate histograms (Using 50 bins for hue, 60 for saturation)
int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins };
float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges, s_ranges };
int channels[] = { 0, 1 };

/// Histograms
Mat hist_base, hist_test1;

/// Calculate the histograms for the HSV images
calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );


calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );

///'3' for Bhattacharyya
double base_test1 = compareHist( hist_base, hist_test1, method );
return base_test1;
}
edit retag flag offensive close merge delete

Comments

Bhattacharyya distance is in [0..1], so your result looks ok.

can you try again, to add the images here ? (and while you're at it, the code, too !)

berak gravatar imageberak ( 2017-10-05 04:25:14 -0600 )edit
1

sorry i am not good with uploading images... can you please take it form here..?

https://imgur.com/Ht5kFvYhttps://imgur.com/4yCb59X

and yes, Bhattacharyya is from (0-1). but it gets close to 0 for max match result. as far as i know. so this seems to me not convincing result for these images. and as for the code, my post has been edited...thanks

reza5630 gravatar imagereza5630 ( 2017-10-05 04:45:56 -0600 )edit
1

can you please check my post again...hope you will find it now...it has been re-attached..

reza5630 gravatar imagereza5630 ( 2017-10-05 05:08:13 -0600 )edit