Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Grayscale to Lbp image

Hi friends i am trying to implement paper on Rapid texture Based Moving Object Detection So in this the first step is to convert grayscale image to lbp image so i have written the following code but it is not producing the desired output So Please if anybody having proper code provide it or state correction in my code.

int main() {

Mat img = cv::imread("im1.jpg");

if (img.empty())
{
   std::cout << "Cannot open image!" << std::endl;
    return -1;
}
Mat greyMat;

cvtColor(img, greyMat, CV_BGR2GRAY);
Mat lbp=greyMat.clone();
long row=greyMat.rows;
long col=greyMat.cols;
for(int i=1;i<greyMat.rows;i++)
{
 for(int j=1;j<greyMat.cols;j++)
 {
    int cp=(int)greyMat.at<uchar>(i,j);
    int pp=0;
    int po=7;
    if(cp<=(int)greyMat.at<uchar>(i,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i,j-1))
    pp+=pow(2,po);
    po--;


    if(cp<=(int)greyMat.at<uchar>(i-1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i-1,j))
    pp+=pow(2,po);
    po--;

    if(cp<=(int)greyMat.at<uchar>(i-1,j+1))
    pp+=1*pow(2,po);
    po--;


    lbp.at<uchar>(i,j)=pp;

 }
}

return 0;

}

click to hide/show revision 2
retagged

Grayscale to Lbp image

Hi friends i am trying to implement paper on Rapid texture Based Moving Object Detection So in this the first step is to convert grayscale image to lbp image so i have written the following code but it is not producing the desired output So Please if anybody having proper code provide it or state correction in my code.

int main() {

Mat img = cv::imread("im1.jpg");

if (img.empty())
{
   std::cout << "Cannot open image!" << std::endl;
    return -1;
}
Mat greyMat;

cvtColor(img, greyMat, CV_BGR2GRAY);
Mat lbp=greyMat.clone();
long row=greyMat.rows;
long col=greyMat.cols;
for(int i=1;i<greyMat.rows;i++)
{
 for(int j=1;j<greyMat.cols;j++)
 {
    int cp=(int)greyMat.at<uchar>(i,j);
    int pp=0;
    int po=7;
    if(cp<=(int)greyMat.at<uchar>(i,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i,j-1))
    pp+=pow(2,po);
    po--;


    if(cp<=(int)greyMat.at<uchar>(i-1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i-1,j))
    pp+=pow(2,po);
    po--;

    if(cp<=(int)greyMat.at<uchar>(i-1,j+1))
    pp+=1*pow(2,po);
    po--;


    lbp.at<uchar>(i,j)=pp;

 }
}

return 0;

}

Grayscale to Lbp image

Hi ![Desired outputActual output(/upfiles/13788229926776895.jpg)Hi friends i am trying to implement paper on Rapid texture Based Moving Object Detection So in this the first step is to convert grayscale image to lbp image so i have written the following code but it is not producing the desired output So Please if anybody having proper code provide it or state correction in my code.

int main() {

Mat img = cv::imread("im1.jpg");

if (img.empty())
{
   std::cout << "Cannot open image!" << std::endl;
    return -1;
}
Mat greyMat;

cvtColor(img, greyMat, CV_BGR2GRAY);
Mat lbp=greyMat.clone();
long row=greyMat.rows;
long col=greyMat.cols;
for(int i=1;i<greyMat.rows;i++)
{
 for(int j=1;j<greyMat.cols;j++)
 {
    int cp=(int)greyMat.at<uchar>(i,j);
    int pp=0;
    int po=7;
    if(cp<=(int)greyMat.at<uchar>(i,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i,j-1))
    pp+=pow(2,po);
    po--;


    if(cp<=(int)greyMat.at<uchar>(i-1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i-1,j))
    pp+=pow(2,po);
    po--;

    if(cp<=(int)greyMat.at<uchar>(i-1,j+1))
    pp+=1*pow(2,po);
    po--;


    lbp.at<uchar>(i,j)=pp;

 }
}

return 0;

}

Grayscale to Lbp image

![Desired Actual outputActual output(/upfiles/13788229926776895.jpg)Hi Desired output Hi friends i am trying to implement paper on Rapid texture Based Moving Object Detection So in this the first step is to convert grayscale image to lbp image so i have written the following code but it is not producing the desired output So Please if anybody having proper code provide it or state correction in my code.

int main() {

Mat img = cv::imread("im1.jpg");

if (img.empty())
{
   std::cout << "Cannot open image!" << std::endl;
    return -1;
}
Mat greyMat;

cvtColor(img, greyMat, CV_BGR2GRAY);
Mat lbp=greyMat.clone();
long row=greyMat.rows;
long col=greyMat.cols;
for(int i=1;i<greyMat.rows;i++)
{
 for(int j=1;j<greyMat.cols;j++)
 {
    int cp=(int)greyMat.at<uchar>(i,j);
    int pp=0;
    int po=7;
    if(cp<=(int)greyMat.at<uchar>(i,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j+1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i+1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i,j-1))
    pp+=pow(2,po);
    po--;


    if(cp<=(int)greyMat.at<uchar>(i-1,j-1))
    pp+=pow(2,po);
    po--;
    if(cp<=(int)greyMat.at<uchar>(i-1,j))
    pp+=pow(2,po);
    po--;

    if(cp<=(int)greyMat.at<uchar>(i-1,j+1))
    pp+=1*pow(2,po);
    po--;


    lbp.at<uchar>(i,j)=pp;

 }
}

return 0;

}