Help:I hava difficult in Circle LBP Code .
2 次查看(过去 30 天)
显示 更早的评论
I'm doing the circular LBP feature,but i have some questions,The result is always white,here's my code,please help me,thanks:
clear;
% 声明默认neighbors为8
I = imread('lena.png');
[rows,cols] = size(I);
neighbors = 8;
radius = 3;
Ibpcode = 0;
CircleLBP = zeros(size(I), 'uint8');
for i = radius+1 : rows-radius
for j = radius+1 : cols-radius
%获得中心像素点的灰度值
centerPixel = I(i, j);
for k = 1 : neighbors
%根据公式计算第k个采样点的坐标
x = i + radius * cos(2.*pi.*k./neighbors);
y = j - radius * sin(2.*pi.*k./neighbors);
%根据取整结果进行双线性插值,得到第k个采样点的灰度值
%1 分别对x,y进行上下取整
x1 = floor(x); %向下取整
x2 = ceil(x); %向上取整
y1 = floor(y); %向下取整
y2 = ceil(y); %向上取整
%2 将坐标映射到0-1之间
tx = x - x1;
ty = y - y1;
%根据0-1之间的x,y的权重计算公式计算权重
w1 = (1 - tx)*(1 - ty);
w2 = tx*(1-ty);
w3 = (1-tx)*ty;
w4 = tx*ty;
%3.根据双线性插值公式计算第k个采样点的灰度值
neighbor = I(x1,y1)*w1 + I(x1,y2)*w2 + I(x2,y1)*w3 + I(x2,y2)*w4;
if(neighbor > centerPixel)
Ibpcode = 2^(neighbors - k -1) + Ibpcode;
end
end
CircleLBP(i,j) = Ibpcode;
end
end
imshow(CircleLBP);
clear;
0 个评论
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!