Ask Your Question
1

Comparing 2 LBPs

asked 2015-10-12 11:25:13 -0600

Leo_ gravatar image

updated 2016-01-31 15:49:46 -0600

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
    Mat temp = imread("Template.jpg",1);
    //image to be compared to
    Mat match = imread("Match.jpg",1);

    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 flag offensive close merge delete

Comments

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

berak gravatar imageberak ( 2015-10-12 23:07:20 -0600 )edit

2 answers

Sort by » oldest newest most voted
5

answered 2015-10-13 02:34:49 -0600

updated 2015-10-13 05:47:25 -0600

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:

image description

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]

image description

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.

image description

(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]

edit flag offensive delete link more

Comments

1

Great answer. Implemented this and getting great results.

Leo_ gravatar imageLeo_ ( 2015-10-13 16:51:16 -0600 )edit
6

answered 2015-10-12 22:40:28 -0600

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.

edit flag offensive delete link more

Comments

Great answer. Implemented this and getting great results.

Leo_ gravatar imageLeo_ ( 2015-10-13 16:51:09 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-10-12 11:25:13 -0600

Seen: 1,543 times

Last updated: Oct 13 '15