# Comparing 2 LBPs

I am using code from bytefish.de to generate my LBPs. If I generate 2 LBPs and their corresponding histograms, what is the best way to compare them?

This is my code so far:

#include "lbp.hpp"
#include "histogram.hpp"

#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;

int main()
{
//template image
//image to be compared to

Mat dst,dst2; // image after preprocessing
Mat lbp,lbp2; // lbp image
Mat hist,hist2;

//Convert to gray
cvtColor(temp, dst, 6);
cvtColor(match, dst2, 6);
//remove noise
GaussianBlur(dst, dst, Size(5,5), 5, 3, BORDER_CONSTANT);
GaussianBlur(dst2, dst2, Size(5,5), 5, 3, BORDER_CONSTANT);
//gets the lbp
lbp::ELBP(dst,lbp,1,8);
lbp::ELBP(dst2,lbp2,1,8);

// normalize(lbp2, lbp2, 0, 255, NORM_MINMAX, CV_8UC1);
//normalize(lbp, lbp, 0, 255, NORM_MINMAX, CV_8UC1);

//get histograms
lbp::histogram(lbp,hist,255);
lbp::histogram(lbp2,hist2,255);

//comparing the 2 LBP histograms
double compareHist = cv::norm(hist-hist2);

cout<<compareHist<<endl;

waitKey(0);
return 0;
}


Basically it gives me a quantifiable number as to how similar these two images are. My question is, how do I improve this result? Whats a better way of acheiving a quantifiable number based on how similar 2 LBPs are? Or is the way I am doing it even right?

Thanks.

edit retag close merge delete

1

those histograms will be quite sparse, so rather try spatial_histogram to improve (get longer feature vectors).

also, maybe cv::compareHist(a,b,HISTCMP_HELLINGER);

if you want classification, and got enough data, you could even train an SVM

( 2015-10-12 23:07:20 -0500 )edit

Sort by » oldest newest most voted

In opencv 3.0 the Alternative Chi-Square (method=CV_COMP_CHISQR_ALT) is introduced. This alternative formula is regularly used for texture comparison. For example, in [1] or in [2] this formula is used.

[1] Ahonen, T., Hadid, A., & Pietikäinen, M. (2004). Face recognition with local binary patterns. In Computer vision-eccv 2004 (pp. 469-481). Springer Berlin Heidelberg.

[2] Shan, C., Gong, S., & McOwan, P. W. (2009). Facial expression recognition based on local binary patterns: A comprehensive study. Image and Vision Computing, 27(6), 803-816.

The formula is as follows:

Moreover, in [1], several possible dissimilarity measures have been proposed to compare the histograms:

• Histogram intersection, Log-likelihood statistic and the aforementioned Chi square

(THIS IS INCLUDED IN CASE OF FACE ANALYSIS AND LBP USING NEAREST-NEIGHBOR CLASSIFIER) Moreover, i think that this "idea" can be extended in order to compare other objects rather than faces, because it can be expected that some of the regions of an object contain more useful information than others.

When the image has been divided into regions, it can be expected that some of the regions contain more useful information than others in terms of distinguishing between people. For example, eyes seem to be an important cue in human face recognition. To take advantage of this, a weight can be set for each region based on the importance of the information it contains. For example,the weighted χ2 statistic becomes: [1]

in which wj is the weight for region j.

For example, in [2], the particular weight set adopted was shown in the figure as follows, which was designed empirically based on the observation.

(Left) A face image divided into 6 7 sub-region. (Right) The weights set for weighted dissimilarity measure. Black squares indicate weight 0.0, dark gray 1.0, light gray 2.0 and white 4.0. [2]

more

1

Great answer. Implemented this and getting great results.

( 2015-10-13 16:51:16 -0500 )edit

AFAIK, for direct matching two face images, the CHI-SQUARE distance gives the best accuracy performance. However, with specific types of image, different distance measures yield varied accuracy rates. Hence, you should carry out an thorough experiment with different distances before making the final choice. See more at Histogram compare in OpenCV.

more

Great answer. Implemented this and getting great results.

( 2015-10-13 16:51:09 -0500 )edit

Official site

GitHub

Wiki

Documentation