Ask Your Question
1

Calculating LBP

asked 2016-03-19 01:15:13 -0500

GANESH PRASAATH L gravatar image

updated 2016-03-19 01:44:18 -0500

I tried calculating Local Binary Pattern for an image.

#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <iostream>
#include <fstream>
#include <sstream>

using namespace cv;
using namespace std;


int main() 
{
    Mat img=imread("G:/Capture.png");
    Mat dst = Mat::zeros(img.rows-2, img.cols-2, CV_8UC1);
    for(int i=1;i<img.rows-1;i++) 
    {
        for(int j=1;j<img.cols-1;j++) 
        {
            uchar center = img.at<uchar>(i,j);
            unsigned char code = 0;
            code |= ((img.at<uchar>(i-1,j-1)) > center) << 7;
            code |= ((img.at<uchar>(i-1,j)) > center) << 6;
            code |= ((img.at<uchar>(i-1,j+1)) > center) << 5;
            code |= ((img.at<uchar>(i,j+1)) > center) << 4;
            code |= ((img.at<uchar>(i+1,j+1)) > center) << 3;
            code |= ((img.at<uchar>(i+1,j)) > center) << 2;
            code |= ((img.at<uchar>(i+1,j-1)) > center) << 1;
            code |= ((img.at<uchar>(i,j-1)) > center) << 0;
            dst.at<uchar>(i-1,j-1) = code;
        }
    }
        imshow("LBP",dst);
        imshow("Source",img);
        waitKey(0);
    return 0;
}

The output images are:image description

The LBP image is not complete.

But What I expect is :

image description

edit retag flag offensive close merge delete

Comments

btw, "local binary pattern", not linear..

berak gravatar imageberak ( 2016-03-19 01:30:00 -0500 )edit

sorry edited the question

GANESH PRASAATH L gravatar imageGANESH PRASAATH L ( 2016-03-19 01:45:24 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-03-19 01:28:28 -0500

berak gravatar image

you need a grayscale image as input, not a color one.

Mat img=imread("G:/Capture.png", IMREAD_GRAYSCALE);
edit flag offensive delete link more

Comments

1

thank you berak it worked

GANESH PRASAATH L gravatar imageGANESH PRASAATH L ( 2016-03-19 01:43:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-03-19 01:15:13 -0500

Seen: 121 times

Last updated: Mar 19 '16