Reputation:
I used imellipse
to select an ellipse as my region of interest (ROI). The issue is that the ellipse I want to select is of around 45 degrees, and, when I use imellipse
, it seems it is 90 degrees either horizontally or vertically.
How can I change the orientation of the ellipse?
Thanks.
Upvotes: 1
Views: 1278
Reputation: 30589
You need to rotate the coordinates of an ellipse. Like this:
npts = 1e4;
t = linspace(0,2*pi,npts);
theta = pi/4;
aspect = [5 1]; % [x y]
x = aspect(1)*sin(t+theta);
y = aspect(2)*cos(t);
plot(x, y);
If you want to use imellipse
to draw the ellipse on an image, you can extract the vertices and transform them:
figure, imshow('pout.tif');
h = imellipse;
exy = h.getVertices
theta = pi/12;
M = [cos(theta), sin(theta); -sin(theta), cos(theta)]
exy_centered = bsxfun(@minus,exy,mean(exy))
exyRot = bsxfun(@plus,exy_centered*M,mean(exy));
hold on
plot(exyRot(:,1),exyRot(:,2),'r') % orig: plot(exy(:,1),exy(:,2),'r')
To fill in the ellipse, creating a mask, use roifill
or roipoly
:
w=getfield(imfinfo('pout.tif'),'Width');
h=getfield(imfinfo('pout.tif'),'Height');
bw = roipoly(zeros(h,w),exyRot(:,1),exyRot(:,2));
Upvotes: 1