Hey everyone, i'm trying to write a code for a method of LBP which consists to calculate the diference between 2 neighboor pixell of each pixel sourrounding the center on a 3x3 window. and then assigned to each neighboring pixel a binary value 1 if the both neighboor pixels values are positive or negative , and 0 if one of them is positive and the other is negative. here's the code :
A = imread('inputImage.png');
grayImage = rgb2gray(A);
[rows, columns, numberOfColorBands] = size(grayImage);
localBinaryPatternImage1 = zeros(size(grayImage));
for row = 2:rows - 1
for col = 2:columns - 1
Ic = grayImage(row, col);
I(6)=grayImage(row-1, col-1);
I(7)=grayImage(row-1, col);
I(8)=grayImage(row-1, col+1);
I(1)=grayImage(row, col+1);
I(2)=grayImage(row+1, col+1);
I(3)=grayImage(row+1, col);
I(4)=grayImage(row+1, col-1);
I(5)=grayImage(row, col-1);
n = 1:8; % n is the number of neighboor pixels
if n == 1
k1(n) =I(8)-I(n); % i'm trying to calculate the difference between the 2 adjacent pixels of the neighboor pixel
k2(n) = I(n+1)- I(n);
elseif n == 8
k1(n) = I(n-1)- I(n);
k2(n) = I1 - I(n);
else
n = 2:7 ;
k1(n) = I(n-1)- I(n);
k2(n) = I(n+1)- I(n);
end
if k1(n)>= 0 & k2(n)>=0 % here i'm sitting the conditions to get a final binary code for each pixel
I(n)= 1;
elseif k1(n)<0 & k2(n)<0
I(n)= 1;
elseif k1(n)>= 0 & k2(n)<0
I(n)= 0;
elseif k1(n)< 0 & k2(n)>= 0
I(n) = 0;
end
% i want to calulate the LBPD, multiplying the weights by the binary code gotten
LBPD = (I(1) + I(2) *2^7 + ...
I(3) * 2^(6) + I(4) * 2^5 + ...
I(5) * 2^4 + I(6) * 2^3 + ...
I(7) * 2^2 + I(8)*2);
localBinaryPatternD(row, col) = LBPD;
end
end
is it the right way to do it ? how can i fix it ? can anyone please help

 채택된 답변

Image Analyst
Image Analyst 2021년 2월 21일

0 개 추천

I didn't delve into your code but if you want to see how I did it, see my attached demo.

댓글 수: 4

nissrine Neyy
nissrine Neyy 2021년 2월 21일
Thank you @Image Analyst for your prompt response, i cheked your code it is clear and siplified way to obtain the LBP, although for my case i have more calculating to do since i'm calculating the differences between adjacent pixels of each of the 8 pixel and then assigning binary values depending on whether they're positive or negative. and it's where i pretty much find difficulties to get it done
To find differences you can use conv2(). Like to find the average difference at each pixel you can do
kernel = [-1, -1, -1; -1, 8, -1; -1, -1, -1] / 8;
outputImage = conv2(double(inputGrayImage), kernel, 'same');
The output will be an image where the pixel value is the average difference between a pixel and its 8 closest neighbors.
nissrine Neyy
nissrine Neyy 2021년 2월 22일
Maybe i misexplained the issue, the differences i'm trying to compute are the diferences between each of the 8 pixels and their 2 adjacents (not a pixel and it's 8 closest neighbors) here's an image to show the idea
Image Analyst
Image Analyst 2021년 2월 22일
You could do that with a set of convolutions, or manually within a nested for loop. See attached demo and adapt the inner part of the loop to do this subtraction thing you want to do.

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

추가 답변 (0개)

질문:

2021년 2월 21일

댓글:

2021년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by