MATLAB:LOCAL BINARY PATTERN CODE


I=rgb2gray(img);
[rows columns numberOfColorBands] = size(I);
LDTP = zeros(size(I));
for row = 2 : rows - 1
for col = 2 : columns - 1
centerPixel = I(row, col);
pixel7=I(row-1, col-1) > centerPixel;
pixel6=I(row-1, col) > centerPixel;
pixel5=I(row-1, col+1) > centerPixel;
pixel4=I(row, col+1) > centerPixel;
pixel3=I(row+1, col+1) > centerPixel;
pixel2=I(row+1, col) > centerPixel;
pixel1=I(row+1, col-1) > centerPixel;
pixel0=I(row, col-1) > centerPixel;
LDTP(row, col) = uint8(...
pixel7 * 2^7 + pixel6 * 2^6 + ...
pixel5 * 2^5 + pixel4 * 2^4 + ...
pixel3 * 2^3 + pixel2 * 2^2 + ...
pixel1 * 2 + pixel0);
end
end
subplot(2,3,2);
imshow(LDTP,[])
title('LBP image')
subplot(2,3,3);
imhist(I)

Leave a Reply

Your email address will not be published. Required fields are marked *