从表示图像的阵列中提取环/扇区区域

时间:2014-05-04 22:01:50

标签: matlab

我试图在MATLAB中从图像的数组表示中提取特征。 这些特征具有圆形(环形)和扇形。如下图所示。我花了很长时间寻找内置函数来做到这一点。我已经设法使用丑陋的循环进行环提取,但不知道从哪个部分开始。任何想法如何在MATLAB中实现这个甚至更好的内置函数都会非常有帮助。

enter image description here

1 个答案:

答案 0 :(得分:2)

这很简单,不需要for循环,例如,如果您的图片是im,请参阅:

[x y]=meshgrid(1:size(im,1));

f =@(x0,y0,r_max,r_min,theta1,theta2) ...
                 (x-x0).^2+(y-y0).^2<=r_max^2 & ...
                 (x-x0).^2+(y-y0).^2>=r_min^2 & ...
                  atan2(y-y0,x-x0)>=theta1 & ...
                  atan2(y-y0,x-x0)<=theta2;

f是一个单线程匿名函数,它接受所有需要的参数并给出所需扇区的掩码。对于响铃,您可以将theta设置为-pi到pi,或者只删除atan中的f部分。例如

r_max=40;
r_min=10;
x0=round(size(im,1)/2); %image center
y0=round(size(im,1)/2); %image center
theta1=deg2rad(10);
theta2=deg2rad(70);

imagesc(f(x0,y0,r_max,r_min,theta1,theta2))
set(gca,'YDir','normal')
axis square

enter image description here