how to implement Uniform local binary pattern for feature extraction?
이전 댓글 표시
i have implemented code for uniform local binary pattern.
i have used the reference paper "Multiresolution Gray-Scale and Rotation Invariant Texture Classification with Local Binary Patterns Timo Ojala, Matti PietikaÈ inen,IEEE, and Topi MaÈenpaÈ".
specify code or method to compute the uniform local binary pattern OR
HELP me in calculating lbpriu2. check whether my code is correct or not.
i have attached the .m files also.
close all;
%computed lbpcode for only centerpixel 70.
image = [47 51 65;62 70 70;80 83 78];
%image = [1 2 3;4 5 6;7 8 9];
%image = [190 211 200; 100 128 126; 193 193 128];
%image=imread('block.jpg');
%image=imread('002A15.jpg');
%if isrgb(image)
% image = rgb2gray(image);
%end
imshow(image);
n1=8;
nghbr=n1;
%fvr = 1;
%for r=1:2:7
[rsize,csize] = size(image);
r = 1;
p = nghbr;
if(rsize < (2*r+1) || csize < (2*r+1) )
error('Too small input image. Should be at least (2*radius+1) x (2*radius+1)');
return;
else
t = zeros(1,p);
lbppr = zeros(rsize,csize);
lbppri = zeros(rsize,csize);
lbppriu2 = zeros(rsize,csize);
x=2;y=2;
fprintf('\nx=%d \t y=%d',x,y);
gc = image(x,y);
fprintf('\ngc=%d',gc);
for i = 1:p
fprintf('\ni=%d',i);
gpx = x + (r * cos((2*3.14*i)/p));
gpy = y - (r * sin((2*3.14*i)/p));
fprintf('\ngpx=%f \t gpy=%f',gpx,gpy);
fpnx = isfloat(gpx);
fpny = isfloat(gpy);
fprintf('\n');
%compute pixel value by bilinear interpolation
if fpnx == 1 || fpny == 1
pixval = biinterp(gpx,gpy,image);
t(1,i) = pixval;
fprintf('\t t(1,%d)=%d',i,t(1,i));
else
t(1,i) = image(gpx,gpy);
fprintf('\t t(1,%d)=%d',i,t(1,i));
end
end
T = zeros(1,p);
s = zeros(1,p);
%for grayscale invariiance
fprintf('\n');
for i = 1:p
T(1,i) = t(1,i) - gc;
fprintf('\t T(1,%d)=%d',i,T(1,i));
if T(1,i) >= 0
s(1,i) = 1;
fprintf('\t s(1,%d)=%d',i,s(1,i));
else
s(1,i) = 0;
fprintf('\t s(1,%d)=%d',i,s(1,i));
end
end
sums = 0;
for i = 1:p
fprintf('\n2p=%d, s=%d',2^(i-1),s(1,i));
sums = sums + (s(1,i) * (2^(i-1)));
end
lbppr(x,y) = sums;
fprintf('\nlbppr(%d,%d)= %d',x,y,lbppr(x,y));
% fprintf('\ndec lbppr=%d\n',lbppr);
%for rotation invariance
lbppr1 = dec2bin(lbppr(x,y));
fprintf('\nbinlbpr=%s',dec2bin(lbppr(x,y)));
minlbprpattern = lbppr1;
for i = 1:p
lbpprpattern = circshift(lbppr1,[1 i]);
fprintf('\ni = %d binlbprpattern=%s',i,lbpprpattern)
a=bin2dec(lbpprpattern); b = bin2dec(minlbprpattern);
fprintf('\na=%d b=%d',a,b);
if a<b
minlbprpattern = lbpprpattern;
end
end
lbppri(x,y) = bin2dec(minlbprpattern);
fprintf('\nlbppri(%d,%d)=%d\n',x,y,lbppri(x,y));
%for uniform patterns
sum = 0;
for i = 2:p
sum = sum + abs(s(1,i) - s(1,p));
end
fprintf('\nsum=%d',sum);
U = abs(s(1,p) - s(1,1)) + sum;
fprintf('\nU=%d',U);
if U <=2
lbppriu2(x,y) = lbppri(x,y);
else
lbppriu2(x,y) = p+1;
end
fprintf('\ndec lbppriu2(%d,%d)=%d\n',x,y,lbppriu2(x,y));
end %if
댓글 수: 1
Imran Riaz
2022년 8월 2일
Your code is not working; there is error on interpolation section.
답변 (1개)
fatma Elsharkawy
2018년 4월 24일
0 개 추천
Hello, I need your Matlab code for Uniform local binary pattern for feature extraction. I'm trying to extract uniform LBP 59 features from a set of images.
카테고리
도움말 센터 및 File Exchange에서 Object Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!