I am trying to extract features from an array representation of an image in MATLAB. The features have a shape of a circle (ring) and a sector. This is shown in the image be
That's pretty easy, with no for loops needed, see for example in case your image is 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
is a one liner anonymous function that accepts all needed parameters and gives a mask of the sector needed. For a ring you can set theta to be -pi to pi, or just delete the atan
part from f
. For example
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