Local Binary Pattern(LBP)

24 ビュー (過去 30 日間)
C N N
C N N 2011 年 9 月 13 日
コメント済み: Image Analyst 2023 年 7 月 16 日
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 件のコメント
Image Analyst
Image Analyst 2019 年 2 月 3 日
Try
imshow(LBP, []);
and try my attached LBP demo.

サインインしてコメントする。

回答 (10 件)

madhulika jain
madhulika jain 2011 年 9 月 22 日
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 日
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 日
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 件のコメント
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh 2021 年 2 月 13 日
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 日
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 件のコメント
Muhammad Amirul Hafiz Sahful Bahri
Muhammad Amirul Hafiz Sahful Bahri 2019 年 3 月 29 日
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 日
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 日
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 日
the code is not giving me any values. can anyone help? thanks!
  3 件のコメント
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 日
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 日
See my attached LBP demo.
  3 件のコメント
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 日
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by