I am trying to execute local binary pattern in MATLAB using the image processing toolbox. When i execute I can't get a LBP image and LBP histogram.
clear all;
close all;
clc;
I=imread('test.png');
figure,imshow(I)
%%Crop
I2 = imcrop(I);
figure, imshow(I2)
w=size(I2,1);
h=size(I2,2);
%%LBP
scale = 2.^[7 6 5; 0 -inf 4; 1 2 3];
for i=2:w-1
for j=2:h-1
J0=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>J0;
I3(i-1,j)=I2(i-1,j)>J0;
I3(i-1,j+1)=I2(i-1,j+1)>J0;
I3(i,j+1)=I2(i,j+1)>J0;
I3(i+1,j+1)=I2(i+1,j+1)>J0;
I3(i+1,j)=I2(i+1,j)>J0;
I3(i+1,j-1)=I2(i+1,j-1)>J0;
I3(i,j-1)=I2(i,j-1)>J0;
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
end
end
figure,imshow(LBP)
figure,imhist(LBP)
what is the issue.i am supposed to get numbers from 0 to 255 but i am not getting it. how to correct it?

댓글 수: 12

Ganesh
Ganesh 2012년 1월 18일
Hi dude!! Can u explain this above code?
C N N
C N N 2012년 1월 18일
Hi.. basically i am implementing Local Binary Pattern(LBP). LBP takes the centre value as threshold.Each of the neighbouring pixels get a value of 1 if it is greater than the threshold and 0 if less than the threshold. So for a 3x3 window, i have 8 neighbouring pixels and i convert the binary number into a value between 0 to 255.
Ganesh
Ganesh 2012년 1월 18일
Thank u !!could u give me some hints about how to create the spatial correlogram of an image? Have u ever used it for image and got it successfully?
C N N
C N N 2012년 1월 19일
what u mean by spatial correlogram? can u explain?
Ganesh
Ganesh 2012년 1월 20일
Spatial pertains to anything that takes up or has the nature of space. When talking of spatial characteristics, they are usually speaking of two-dimensional characteristics.
Ganesh
Ganesh 2012년 1월 20일
And Correlogram means, in the analysis of data, a correlogram is an image of correlation statistics. For example, in time series analysis, a correlogram, also known as an autocorrelation plot, is a plot of the sample autocorrelations versus (the time lags).
If cross-correlation is used, the result is called a cross-correlogram. The correlogram is a commonly used tool for checking randomness in a data set. This randomness is ascertained by computing autocorrelations for data values at varying time lags. If random, such autocorrelations should be near zero for any and all time-lag separations. If non-random, then one or more of the autocorrelations will be significantly non-zero.
In addition, correlograms are used in the model identification stage for Box–Jenkins autoregressive moving average time series models. Autocorrelations should be near-zero for randomness; if the analyst does not check for randomness, then the validity of many of the statistical conclusions becomes suspect. The correlogram is an excellent way of checking for such randomness.
Ganesh
Ganesh 2012년 2월 1일
Halo sir!Y no reply from u? what about answer for my question
Walter Roberson
Walter Roberson 2012년 2월 1일
Ganesh, the answer is NO. Someone who has not heard of Correlograms would not have "got it successfully".
You should not post in someone else's Question, ask them something on a different topic completely, and expect that they will have an answer for you.
Your own Question on correlograms is still open. You can post a reminder to people in your own Question. I would suggest that you might want to copy your above descriptions in to your own Question for clarification to people.
I=imread('frame1.jpg');
%figure;imshow(I);title('Original Image');
I2 = imcrop(I);
IM2=rgb2gray(I);
%figure, imshow(I2)
%figure;imhist(IM2);title('convert Image');
w=size(I2,1);
h=size(I2,2);
scale = 2.^[7 6 5; 0 -inf 4; 1 2 3];
for i=2:w-1
for j=2:h-1
J0=I2(i,j);
I3(i-1,j-1)=I2(i-1,j-1)>J0;
I3(i-1,j)=I2(i-1,j)>J0;
I3(i-1,j+1)=I2(i-1,j+1)>J0;
I3(i,j+1)=I2(i,j+1)>J0;
I3(i+1,j+1)=I2(i+1,j+1)>J0;
I3(i+1,j)=I2(i+1,j)>J0;
I3(i+1,j-1)=I2(i+1,j-1)>J0;
I3(i,j-1)=I2(i,j-1)>J0;
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
end
end
figure;imshow(I);title('Original1 Image');
figure;imshow(I2);title('Cropped Image');
figure;imshow(LBP);title('Classify Image Using LBP');
figure;imhist(IM2);title('Histogram Image');
kalai selvi
kalai selvi 2018년 2월 3일
i got hist try it thanks
Try
imshow(LBP, []);
and try my attached LBP demo.

댓글을 달려면 로그인하십시오.

답변 (10개)

madhulika jain
madhulika jain 2011년 9월 22일

1 개 추천

I think you shpuld be getting LBP in the range 0 to 255. I ran this code and i got the values in this range only

댓글 수: 1

C N N
C N N 2011년 9월 22일
The problem with this code that after you get LBP, you need to convert it to uint8 before displaying it.

댓글을 달려면 로그인하십시오.

Izzo
Izzo 2011년 12월 3일

1 개 추천

hey i think i got your problem, because i already did LBP. First, make sure that u have converted the image into grayscale form. Second, you have to replace the test image with the new LBP image, therefore: instead of this code
LBP(i,j)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
try to change into:
I2(i-1,j-1)=I3(i-1,j-1)*2^7+I3(i-1,j)*2^6+I3(i-1,j+1)*2^5+I3(i,j+1)*2^4+I3(i+1,j+1)*2^3+I3(i+1,j)*2^2+I3(i+1,j-1)*2^1+I3(i,j-1)*2^0;
because i have problem like that too, then my supervisor solve into this for me :P
Image Analyst
Image Analyst 2011년 9월 22일

0 개 추천

Change the last few lines of your code to this:
subplot(2,2,3);
imshow(LBP, []);
subplot(2,2,4);
[pixelCounts, GLs] = imhist(uint8(LBP));
bar(GLs, pixelCounts);

댓글 수: 10

C N N
C N N 2011년 9월 22일
how is this useful? can u explain? thanks.
Image Analyst
Image Analyst 2011년 12월 5일
Because LBP is a double but instead of your LBP array being in the range of 0-1 like imshow() requires for a double, your array has a range of 0-255, as if it were a uint8, but it's not. So to get imshow() to display arrays from the max to the min for whatever range they have, rather than assuming they live in the range of 0-1, you need to add the [] as an argument. If you do that, voila!, you'll see your image. Just try it.
Aquib
Aquib 2012년 10월 27일
what does this code indicate
[pixelCounts, GLs] = imhist(uint8(LBP));
bar(GLs, pixelCounts);
can u explain plz???????
Image Analyst
Image Analyst 2012년 10월 27일
It gets a histogram (frequency of occurrence) of the LBP image, and then plots it with a bar chart.
Aquib
Aquib 2012년 10월 28일
Sir i had 1 more question regarding this code i.e, what is the difference between imshow(LBP, []); and imshow(LBP); since i wrote both the code the result form the code:imshow(LBP, []); is different as it displays an grayscale image while as if i write the code: imshow(LBP); it displays an image with either value 1 or 0 ie an binary image.....
Image Analyst
Image Analyst 2012년 10월 28일
편집: Image Analyst 2012년 10월 28일
I almost always use [] because it scales the image so you can see it. For uint8 or binary (logical) images, it will automatically scale to 0-255 or 0-1 respectively. However for single or double images, you won't see anything unless you use [] OR your image has values only between 0.0 and 1.0. If you had a uint8 image that went, say, only from 0-42, then it would appear dark, but it you did [] it would map linearly from 0-42 into 0-255 so you'd be able to see it better. This is what imagesc() does except without the ridiculous colormap that imagesc() applies by default. However if you're visually comparing it to other uint8 images, you might want to use [0 255] instead of [].
By the way, I've posted full LBP demos here in the Answers forum and newsgroup before - you might want to look for it.
Aquib
Aquib 2012년 10월 31일
Thank you sir i really appreciate you help
Azinuddin Aziz
Azinuddin Aziz 2015년 11월 29일
Sir, it is possible for this LBP histogram to be an input of svm classification?. If possible, how we can convert this histogram into a vector for classification?
Hi,
I have a cell array data of grayscale images 20x5. (20 images at 5 frames)
I want to use LBP to analyze the background scatter points of my images and see if I can find any differences between their values, as my data covers the healthy and unhealthy patients.
Is there anyone who can help me for that. I have been using this code;
features = extractLBPFeatures(images{20,1})
subplot(2,2,3);
imshow(features, []);
subplot(2,2,4);
[pixelCounts, GLs] = imhist(uint8(features));
bar(GLs, pixelCounts);
But I think it does not show me what I want. As the output is a single array. I am not very familiar with LBP, can you please hep me regarding how the output should be?
Walter Roberson
Walter Roberson 2021년 2월 14일
But I think it does not show me what I want
We do not have your image to test with, and we do not know what kinds of output you expect to see.

댓글을 달려면 로그인하십시오.

remo
remo 2011년 12월 1일

0 개 추천

hi CNN,
Sorry for being a Noob. I just cant understand why you use 'scale = 2.^[7 6 5; 0 -inf 4; 1 2 3]; ' in this program. can you explain?

댓글 수: 7

Image Analyst
Image Analyst 2011년 12월 2일
The local binary pattern is a comparison of the middle pixel in a 3x3 window with all the pixels running around it in a clockwise pattern starting at the upper left. Those are the powers of 2, like this
7 6 5
0 4
1 2 3
So you compare and add up the pixels like it's a binary pattern of 1's and 0's multiplied by the power of 2 for that position around the middle pixels. So
0 0 0
1 1
1 1 1
would be like 0 * 2^7 + 0 * 2^6 + 0 * 2^5 + 1 *2^4 + 1 * 2^3 + 1 * 2^2 + 1 * 2^1 + 1 * 2^0, which is 31.
Image Analyst
Image Analyst 2011년 12월 2일
Sorry the formatting squished the middle rows. The middle element of the 3x3 arrays I wrote should have a blank space in them.
remo
remo 2011년 12월 8일
hi,thank you Image Analyst.
Now i stuck at concatenating LBP histogram to create a feature histogram.Any ideas?
Image Analyst
Image Analyst 2011년 12월 9일
I don't know what you mean. Concatenate the histogram onto *what*? What is a "feature histogram"? I know what a feature vector is but not a feature histogram.
C N N
C N N 2012년 1월 18일
remo, u want to create a histogram is it? use a function called hist in MATLAB.
hi, I would like to know how did you get those number [ 7 6 5; 0 -inf 4; 1 2 3] ?
Did you calculate it?
Image Analyst
Image Analyst 2019년 3월 29일
Unhide the comments above and you'll see a desciption of how those are computed.

댓글을 달려면 로그인하십시오.

anusha
anusha 2014년 9월 24일
편집: DGM 2023년 2월 11일

0 개 추천

u can try this code
clear all;
close all;
I=imread('cameraman.tif');
I=rgb2gray(I);
I1=imcrop(I);
[w h]=size(I1);
for i=2:w-1
for j=2:h-1
val=I1(i,j);
scale=2.^[0 1 2;7 -inf 3;6 5 4];
mat=[I1(i-1,j-1) I1(i-1,j) I1(i-1,j+1);
I1(i,j-1) I1(i,j) I1(i,j+1);
I1(i+1,j-1) I1(i+1,j) I1(i+1,j+1)];
mat=mat>=val;
fin=mat.*scale;
I1(i,j)=sum(sum(fin));
end
end
imshow(I1,[]);
Nikolay S.
Nikolay S. 2015년 3월 16일

0 개 추천

You can try one of the following LBP implementations: http://www.mathworks.com/matlabcentral/fileexchange/49787-shift-based-lbp http://www.mathworks.com/matlabcentral/fileexchange/36484-local-binary-patterns I'm using both for a while, updating them fomr time to time.
Ktk
Ktk 2017년 10월 29일

0 개 추천

the code is not giving me any values. can anyone help? thanks!

댓글 수: 3

Image Analyst
Image Analyst 2017년 10월 30일
WHAT code?
Attached is my local binary pattern demo. Adapt as needed.
SATISH SONWANE
SATISH SONWANE 2022년 6월 1일
Why did you use LSB?
Image Analyst
Image Analyst 2022년 6월 1일
@SATISH SONWANE, isn't that the usual way? You can change it if you want. Why would you want to?

댓글을 달려면 로그인하십시오.

Vrushali Patil
Vrushali Patil 2020년 4월 2일

0 개 추천

Can anyone please help me to apply lbp on image frames directly without croping the image?

댓글 수: 1

Image Analyst
Image Analyst 2020년 4월 2일
Who said you had to crop the image? Just go ahead and do it on your image without cropping it if you don't want to crop it. What's the problem?

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2020년 4월 2일

0 개 추천

See my attached LBP demo.

댓글 수: 3

PAVITHRA
PAVITHRA 2023년 2월 22일
whether ryou demo code will suitable for brain tumor image?
PAVITHRA
PAVITHRA 2023년 2월 22일
If i run this demo code for brain tumor image,the lbp image becomes red color why?
Image Analyst
Image Analyst 2023년 2월 22일
@PAVITHRA I have no idea what your code does. When anyone runs my code, this is what they'll see:
If you want me to look at your code, start a new question and attach your code and image.

댓글을 달려면 로그인하십시오.

Dehia
Dehia 2023년 7월 15일

0 개 추천

Is it normal to have a large number of zeros and a few non-zero values in the LBP feature array?

댓글 수: 1

Image Analyst
Image Analyst 2023년 7월 16일
For 3x3 submatrices where all the values are the same, you'd get zero. This can happen fairly often.

댓글을 달려면 로그인하십시오.

질문:

2011년 9월 13일

댓글:

2023년 7월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by