forked from tapabrata-chakraborti/LBP-LDP-LOOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lbp.m
64 lines (48 loc) · 1.38 KB
/
lbp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
% Demo: A simple 3x3 LBP (local binary pattern) code.
% Cite: T. Chakraborti, B. McCane, S. Mills, and U. Pal, "LOOP: Descriptor:
% Encoding Repeated Local Patternsfor Fine-grained Visual Identification of
% Lepidoptera", arXiv:1710.09317.
clear all
close all
% pre-processing
I=imread('peppers.png'); %input image
imshow(I); %display input image
I=im2double(I); %convert to double
if size(I,3)==3
I=rgb2gray(I); %convert to grayscale if rgb
end
figure;
imshow(I); %display grayscale image
[m,n]=size(I); %get the size of image
%initialise variable
z=zeros(8,1);
b=zeros(m,n);
% LBP calculation
for i=2:m-1
for j=2:n-1
t=1;
for k=-1:1
for l=-1:1
if (k~=0)||(l~=0)
if (I(i+k,j+l)-I(i,j)<0) %threshold to generate bit
z(t)=0;
else
z(t)=1;
end
t=t+1;
end
end
end
for t=0:7
b(i,j)=b(i,j)+((2^t)*z(t+1)); %binary to decimal conversion
end
end
end
b=uint8(b); %convert decimal 2-d matrix to image
figure;
imshow(b); %display LBP image
%LBP Histogram
H=imhist(b); %find histogram
figure;
bar(H); %display histogram
%%--------------------------------------------------------------%%