MATLAB: Plot orientations using quiver only in the mask region…

plot quiver

[rows, cols] = size(orient);
len = 0.8*spacing;
s_orient = orient(spacing:spacing:rows-spacing, spacing:spacing:cols-spacing);
xoff = len/2*cos(s_orient);
yoff = len/2*sin(s_orient);
[x,y] = meshgrid(spacing:spacing:cols-spacing, ...
spacing:spacing:rows-spacing);
x = x-xoff;
y = y-yoff;
u = xoff*2;
v = yoff*2;
figure, imshow(I), hold on;
quiver(x,y,u,v,0,'.','linewidth',1,'color','r'); hold off;
i want to plot the quiver only in non-zero positions of "orient"…

Best Answer

I think you'll have to go down your list of x and y and determine if the point is inside or outside the ROI using the inpolygon() function.
rowsToKeep = false(1, length(x));
for k = 1 : length(x)
if inpolygon(x(k), y(k), xSquare1, ySquare1)
rowsToKeep(k) = true;
end
if inpolygon(x(k), y(k), xSquare2, ySquare2)
rowsToKeep(k) = true;
end
if inpolygon(x(k), y(k), xOval1, yOval1)
rowsToKeep(k) = true;
end
if inpolygon(x(k), y(k), xOval2, yOval2)
rowsToKeep(k) = true;
end
end
% Extract only the good points.
x = x(rowsToKeep);
y = y(rowsToKeep);