【发布时间】:2012-03-04 19:28:27
【问题描述】:
我正在尝试实现精明的边缘检测器。我编写了一些代码来生成我认为在非最大值抑制阶段之前应该正确的代码,但是当我运行它时,我得到的图像几乎显示了轮廓,但这不是我的预期结果。
我花了几个小时试图修复它,但找不到哪里出错了。谁能指出我正确的方向?
% Set direction to either 0, 45, -45 or 90 depending on angle.
[x,y]=size(f1);
for i=1:x-1,
for j=1:y-1,
if ((gradAngle(i,j)>67.5 && gradAngle(i,j)<=90) || (gradAngle(i,j)>=-90 && gradAngle(i,j)<=-67.5))
gradDirection(i,j)=0;
elseif ((gradAngle(i,j)>22.5 && gradAngle(i,j)<=67.5))
gradDirection(i,j)=45;
elseif ((gradAngle(i,j)>-22.5 && gradAngle(i,j)<=22.5))
gradDirection(i,j)=90;
elseif ((gradAngle(i,j)>-67.5 && gradAngle(i,j)<=-22.5))
gradDirection(i,j)=-45;
end
end
end
% Non-maxima suppression.
% Compare to neighbours and set as 0 if smaller than either of them
for i=2:x-2,
for j=2:y-2,
if(gradDirection(i,j)==90)
if (gradDirection(i,j)<(gradDirection(i,j-1) | gradDirection(i,j+1)))
gradDirection(i,j)=0;
end
end
if(gradDirection(i,j)==45)
if (gradDirection(i,j)<(gradDirection(i+1,j-1) | gradDirection(i-1,j+1)))
gradDirection(i,j)=0;
end
end
if(gradDirection(i,j)==-45)
if (gradDirection(i,j)<(gradDirection(i-1,j-1) | gradDirection(i+1,j+1)))
gradDirection(i,j)=0;
end
end
end
end
【问题讨论】:
-
到底是什么问题?你期待什么?
标签: matlab image-processing edge-detection