RK2015
RK2015

Reputation: 397

Comparing 2 LBPs (OpenCV C++)

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?

Thanks.

Upvotes: 2

Views: 842

Answers (1)

nv3
nv3

Reputation: 396

The LBP just gives you a (rather large) feature vector. To make anything useful of that you would typically process many example images (all belong to the class of images that you define as "being alike") and then use a Support Vector Machine to train a behavior that lets it recognize this likeness.

Just comparing two LPBs does normally not give you much information about the likeness of two images. To see that: Just translate the first image by one cell size of your LBP algorithm. The second LBP will then appear to be a shifted version of the first LBP. As you normally have no information as to how images are aligned or rotated it very difficult to compare two LBPs by some simple logic.

Upvotes: 1

Related Questions