How to rotate imellipse

16 visualizaciones (últimos 30 días)
erik
erik el 23 de Mayo de 2013
Respondida: Tim Jackman el 25 de Sept. de 2018
Hello fellow Matlab users,
I'm currently using the imellipse function to draw an ellipse on an image. I would like to rotate the ellipse interactively. However I cannot get this to work. Does anyone have experience with rotating ellipses? Please share, it would help me out a lot!
With kind regards,
Erik Groot Jebbink

Respuesta aceptada

Image Analyst
Image Analyst el 23 de Mayo de 2013
See my demo. It doesn't use imellipse() so you can't have handles to click and drag out new a size or angle. So you'd need to have a GUI with some sliders to allow the user to set new parameters for the major axis length, minor axis length, center location, and angle or orientation.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Parameterize the equation.
t = linspace(0, 360,1000);
phaseShift = 20;
xAmplitude = 2;
yAmplitude = 1;
x = xAmplitude * sind(t + phaseShift);
y = yAmplitude * cosd(t);
% Now plot the rotated ellipse.
plot(x, y, 'b-', 'LineWidth', 2);
axis equal
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Rotated Ellipses', 'FontSize', fontSize);
text(-1.75, 1.4, 'Parametric --', 'Color', 'b', 'FontSize', fontSize);
% Now plot another ellipse and multiply it by a rotation matrix.
% http://www.maa.org/joma/Volume8/Kalman/General.html
rotationAngle = 30;
transformMatrix = [cosd(rotationAngle), sind(rotationAngle);...
-sind(rotationAngle), cosd(rotationAngle)]
xAligned = xAmplitude * sind(t);
yAligned = yAmplitude * cosd(t);
xyAligned = [xAligned; yAligned]';
xyRotated = xyAligned * transformMatrix;
xRotated = xyRotated(:, 1);
yRotated = xyRotated(:, 2);
hold on;
plot(xRotated, yRotated, 'g-', 'LineWidth', 2);
% Plot a line at 30 degrees
slope = tand(30);
x1 = min(x(:));
y1 = slope * x1;
x2 = max(x(:));
y2 = slope * x2;
line([x1 x2], [y1 y2], 'Color', 'r');
text(-1.75, 1.25, 'Rotation Matrix --', 'Color', 'g', 'FontSize', fontSize);
text(-1.75, 1.1, '30 Degree Line --', 'Color', 'r', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

Más respuestas (3)

Tim Jackman
Tim Jackman el 25 de Sept. de 2018
Beginning in R2018b, you can create an interactive ellipse ROI using the drawellipse function. This new ROI supports interactive rotation.

Matt J
Matt J el 23 de Mayo de 2013
I believe imellipse objects are 4 DOF only :-(

erik
erik el 27 de Mayo de 2013
Image Analyst, thank you for your contribution. I created a small gui with some sliders to move the ellipse around.
  3 comentarios
Image Analyst
Image Analyst el 27 de Oct. de 2013
as hz, I already pretty much gave code. All you need to do is to put it into a function called DrawEllipse which you call from the sliders. In the slider callbacks you set rotationAngle or some x and y offset/shift/translation, then call DrawEllipse passing those in.
YUKAi LIU
YUKAi LIU el 10 de Mayo de 2018
Editada: Matt J el 10 de Mayo de 2018
is it possible to share this code to me?

Iniciar sesión para comentar.

Categorías

Más información sobre Live Scripts and Functions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by