Ask Your Question
0

How to use LBP to visualize results ?

asked 2016-12-15 01:54:44 -0500

Nbb gravatar image

How do I use the LBP and how can I visualize its results ? The guide here http://docs.opencv.org/2.4/modules/co... doesnt show me how to display the images shown in the guide

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-12-15 02:06:31 -0500

berak gravatar image

i'm afraid, you can't (without hacking the library)

the lbp images are not kept (only the histograms are).

if you really need this, you'll have to copy the elbp function to your own code, and apply a grayscale image to that.

edit flag offensive delete link more
1

answered 2016-12-16 05:56:00 -0500

KirtiSwagat gravatar image

updated 2016-12-16 08:27:19 -0500

berak gravatar image
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <limits.h>
#include <math.h>
#include <iostream>


using namespace std;
using namespace cv;

Mat LBP(Mat src_image)
{
    bool value=true;
    Mat Image(src_image.rows, src_image.cols, CV_8UC1);
    Mat lbp(src_image.rows, src_image.cols, CV_8UC1);

    if (src_image.channels() == 3)
        cvtColor(src_image, Image, CV_BGR2GRAY);

    unsigned center = 0;
    unsigned center_lbp = 0;

    for (int row = 1; row < Image.rows-1; row++)
    {
        for (int col = 1; col < Image.cols-1; col++)
        {
            center = Image.at<uchar>(row, col);
            center_lbp = 0;

            if (center <= Image.at<uchar>(row-1, col-1))
                center_lbp += 1;

            if (center <= Image.at<uchar>(row-1, col))
                center_lbp += 2;//2

            if (center <= Image.at<uchar>(row-1, col+1))
                center_lbp += 4;//4

            if (center <= Image.at<uchar>(row, col+1 ))
                center_lbp += 8;//8

            if (center <= Image.at<uchar>(row+1, col+1))
                center_lbp += 16;//16

            if (center <= Image.at<uchar>(row+1, col))
                center_lbp += 32;//32

            if (center <= Image.at<uchar>(row+1,col-1))
                center_lbp += 64;//64

            if (center <= Image.at<uchar>(row,col-1))
                center_lbp += 128;//128
            lbp.at<uchar>(row, col) = center_lbp;
        }
    }

    if(value == true)
    {
        namedWindow( "image LBP", CV_WINDOW_FREERATIO);
        imshow("image_LBP", lbp);
        imwrite("/root/Desktop/LBP.jpg",lbp);
        waitKey(0);
        imshow("grayscale",Image);
        waitKey(0);
    }
    else
    {
      cv::destroyWindow("image LBP");
      cv::destroyWindow("grayscale");
    }

    return lbp;

}

int main()
{
    string filename="1.jpg";
    Mat frame1;
    frame1= imread("/root/Desktop/"+filename);
    LBP(frame1);
}

image description image description

edit flag offensive delete link more

Comments

next time, use the "10101" button, to format your code !

berak gravatar imageberak ( 2016-12-16 06:17:49 -0500 )edit

also note, that yours is the "olbp" (square neighbourhood), while opencv uses "elbp" (circle)

berak gravatar imageberak ( 2016-12-16 06:18:49 -0500 )edit
1

@break Thank you very much... :-)

KirtiSwagat gravatar imageKirtiSwagat ( 2016-12-16 07:06:37 -0500 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-12-15 01:54:44 -0500

Seen: 252 times

Last updated: Dec 16 '16