| Current Path : /var/www/html/srdubey/publications/ |
| Current File : /var/www/html/srdubey/publications/2019_FDLBP.m |
% FDLBP returns the Frequency Decoded Local Binary Pattern histogram for an input image.
% The original code of LBP is used and updated to the FDLBP by Dr. Shiv Ram Dubey, IIIT Sri City.
% This code can be used only for the academic and research purposes and can not be used for any commercial purposes.
% Cite the paper
% 'S.R. Dubey, Face Retrieval using Frequency Decoded Local Descriptor. Multimedia Tools and Applications, 2018.'
% In case you are using this code.
function des=FDLBP(path_image)
% path_image='datasets\ExtYaleCropped\yaleB02\yaleB02_P00A+000E-35.pgm';
im=imresize(imread(path_image),[64 64]); % Reading the image and resizing to 64 * 64
if length(size(im))==3 % Convert into gray in case of color image
im=rgb2gray(im);
end
% Image Filtering
img1(:,:,1)=imfilter(im,[1,1,1;1,1,1;1,1,1]/9);
img1(:,:,2)=imfilter(im,[0,-1,0;-1,4,-1;0,-1,0]);
img1(:,:,3)=imfilter(im,[-1,0,-1;0,4,0;-1,0,-1]);
img2(:,:,1)=imfilter(im,[1,1,1;1,1,1;1,1,1]/9);
img2(:,:,2)=imfilter(im,[1,2,1;0,0,0;-1,-2,-1]);
img2(:,:,3)=imfilter(im,[-1,0,1;-2,0,2;-1,0,1]);
des1=lbp12(img1);des2=lbp12(img2);
des=[des1 des2]; % Feature Concatenation
des=des/sum(des); % Final Feature Normalization
end
function result1 = lbp12(varargin) % image,radius,neighbors,mapping,mode)
error(nargchk(1,5,nargin));
image=varargin{1};
d_image=double(image);
if nargin==1
spoints=[-1 -1; -1 0; -1 1; 0 -1; -0 1; 1 -1; 1 0; 1 1];
neighbors=8;
mapping=0;
mode='h';
end
if (nargin == 2) && (length(varargin{2}) == 1)
error('Input arguments');
end
if (nargin > 2) && (length(varargin{2}) == 1)
radius=varargin{2};
neighbors=varargin{3};
spoints=zeros(neighbors,2);
% Angle step.
a = 2*pi/neighbors;
for i = 1:neighbors
spoints(i,1) = -radius*sin((i-1)*a);
spoints(i,2) = radius*cos((i-1)*a);
end
if(nargin >= 4)
mapping=varargin{4};
if(isstruct(mapping) && mapping.samples ~= neighbors)
error('Incompatible mapping');
end
else
mapping=0;
end
if(nargin >= 5)
mode=varargin{5};
else
mode='h';
end
end
if (nargin > 1) && (length(varargin{2}) > 1)
spoints=varargin{2};
neighbors=size(spoints,1);
if(nargin >= 3)
mapping=varargin{3};
if(isstruct(mapping) && mapping.samples ~= neighbors)
error('Incompatible mapping');
end
else
mapping=0;
end
if(nargin >= 4)
mode=varargin{4};
else
mode='h';
end
end
% Determine the dimensions of the input image.
[ysize xsize csize] = size(image);
miny=min(spoints(:,1));
maxy=max(spoints(:,1));
minx=min(spoints(:,2));
maxx=max(spoints(:,2));
% Block size, each LBP code is computed within a block of size bsizey*bsizex
bsizey=ceil(max(maxy,0))-floor(min(miny,0))+1;
bsizex=ceil(max(maxx,0))-floor(min(minx,0))+1;
% Coordinates of origin (0,0) in the block
origy=1-floor(min(miny,0));
origx=1-floor(min(minx,0));
% Minimum allowed size for the input image depends
% on the radius of the used LBP operator.
if(xsize < bsizex || ysize < bsizey)
error('Too small input image. Should be at least (2*radius+1) x (2*radius+1)');
end
% Calculate dx and dy;
dx = xsize - bsizex;
dy = ysize - bsizey;
% Fill the center pixel matrix C.
C = image(origy:origy+dy,origx:origx+dx,:);
d_C = double(C);
bins = 2^neighbors;
% Initialize the result matrix with zeros.
result=zeros(dy+1,dx+1,8);
%Compute the LBP code image
for i = 1:neighbors
y = spoints(i,1)+origy;
x = spoints(i,2)+origx;
% Calculate floors, ceils and rounds for the x and y.
fy = floor(y); cy = ceil(y); ry = round(y);
fx = floor(x); cx = ceil(x); rx = round(x);
% Check if interpolation is needed.
if (abs(x - rx) < 1e-6) && (abs(y - ry) < 1e-6)
% Interpolation is not needed, use original datatypes
N = image(ry:ry+dy,rx:rx+dx,:);
D = N >= C;
else
% Interpolation needed, use double type images
ty = y - fy;
tx = x - fx;
% Calculate the interpolation weights.
w1 = (1 - tx) * (1 - ty);
w2 = tx * (1 - ty);
w3 = (1 - tx) * ty ;
w4 = tx * ty ;
% Compute interpolated pixel values
N = w1*d_image(fy:fy+dy,fx:fx+dx,:) + w2*d_image(fy:fy+dy,cx:cx+dx,:) + ...
w3*d_image(cy:cy+dy,fx:fx+dx,:) + w4*d_image(cy:cy+dy,cx:cx+dx,:);
D = N >= d_C;
end
D1=ones(size(C,1),size(C,2));
for ij=1:size(C,3)
D1=D1 + D(:,:,ij)*(2.^(ij-1));
end
% Update the result matrix.
v = 2^(i-1);
for ij=1:2.^(size(C,3)) % Applying the decoder concept
D2 = D1==ij;
result(:,:,ij) = result(:,:,ij) + v*D2;
end
end
%Apply mapping if it is defined
if isstruct(mapping)
bins = mapping.num;
for i = 1:size(result,1)
for j = 1:size(result,2)
result(i,j,:) = mapping.table(result(i,j,:)+1);
end
end
end
result1=[];
for ij=1:2.^(size(C,3))
re=result(:,:,ij);
result1=[result1 hist(re(:),0:(bins-1))];
end
end