Local binary pattern varient
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Image Analyst
2021년 2월 21일
I didn't delve into your code but if you want to see how I did it, see my attached demo.
댓글 수: 4
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!