# Calculating LBP

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 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:

The LBP image is not complete.

But What I expect is :

edit retag close merge delete

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

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

sorry edited the question

( 2016-03-19 01:45:24 -0500 )edit

Sort by ยป oldest newest most voted

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

Mat img=imread("G:/Capture.png", IMREAD_GRAYSCALE);

more

1

thank you berak it worked

( 2016-03-19 01:43:34 -0500 )edit

Official site

GitHub

Wiki

Documentation