Azzera filtri
Azzera filtri

Local binary pattern varient

3 visualizzazioni (ultimi 30 giorni)
nissrine Neyy
nissrine Neyy il 21 Feb 2021
Commentato: Image Analyst il 22 Feb 2021
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

Risposta accettata

Image Analyst
Image Analyst il 21 Feb 2021
I didn't delve into your code but if you want to see how I did it, see my attached demo.
  4 Commenti
nissrine Neyy
nissrine Neyy il 22 Feb 2021
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 il 22 Feb 2021
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by