-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathILBP81ri.m
106 lines (80 loc) · 2.56 KB
/
ILBP81ri.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function [h] = ILBP81ri(X)
%Im=rgb2gray(X);
%ILBP81ri texture features
%
%INPUT:
%X: grey-scale image
%
%OUTPUT:
%h: featureVector
%
% Image size
[L M] = size(X);
codesILBP81 = codeILBP81(X);
histCodesILBP81 = sum(hist(codesILBP81,0:511)');
lut81 = lutRotInv('CCR81ri');
nbins = length(unique(lut81));
histCodesILBP81ri = zeros(1,nbins);
for p = 1:length(histCodesILBP81);
r = lut81(p);
histCodesILBP81ri(r+1) = histCodesILBP81ri(r+1) + histCodesILBP81(p);
end
h = histCodesILBP81ri / ((L-2)*(M-2));
%Remove the first bin (is always 0)
h(1) = [];
end
function [Xcod] = codeILBP81(X)
%
% [Xcod] = Features_CCR81(X,T)
%
% Computes CCR81 codes of a single channel texture image
%
% Inputs:
% X - Single channel texture image (at least 3x3 pixels)
% T - Binarization threshold
%
% Outputs:
% Xcod - Image with CCR81 codes
% Coeficients used in bilinear interpolation
sqrt_2 = 1.4142;
center = (1-1/sqrt_2)^2;
corner = (1/sqrt_2)^2;
diagon = (1-1/sqrt_2)*(1/sqrt_2);
% Conversion to avoid errors when using sort, unique...
X = double(X);
% Image size
[L M] = size(X);
% Displacement directions
north = 1:L; % N: North
south = 3:L+2; % S: South
equad = 2:L+1; % equator
east = 3:M+2; % E: East
west = 1:M; % W: West
meri = 2:M+1; % meridian
% 0: No displacement
[X0, XN, XNE, XE, XSE, XS, XSW, XNW, XW] = deal(zeros(L+2,M+2));
[pN, pNE, pE, pSE, pS, pSW, pW, pNW, p0] = deal(zeros(L+2,M+2));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pN (north,meri) = diagon*X ;
pS (south,meri) = diagon*X ;
pE (equad,east) = diagon*X ;
pW (equad,west) = diagon*X ;
pNE(north,east) = X ;
pNW(north,west) = X ;
pSE(south,east) = X ;
pSW(south,west) = X ;
p0 (equad,meri) = center*X ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XN(north,meri) = X;
XS(south,meri) = X;
XE(equad,east) = X;
XW(equad,west) = X;
X0(equad,meri) = X;
XSE = round(corner*pSE + pS + pE + p0);
XSW = round(corner*pSW + pS + pW + p0);
XNW = round(corner*pNW + pN + pW + p0);
XNE = round(corner*pNE + pN + pE + p0);
T = round((XN + XS + XE + XW + XNE + XNW + XSE + XSW + X0)/9);
X0 = 256*(XSE>=T) + 128*(XS>=T) + 64*(XSW>=T) + 32*(XE>=T) + 16*(X0>=T) + 8*(XW>=T) + 4*(XNE>=T) + 2*(XN>=T) + (XNW>=T);
Xcod = X0(3:L,3:M);
end