How can I imrotate without changing the image axes in a GUI?

1 view (last 30 days)
I'm trying to rotate a circle in a GUI I'm making to mimic a wheel that rotates. I have the wheel, and the image does rotate, but the background rotates with the wheel and so the image shrinks and then expands as a square, which is not what I need. I need just the circle to move or, at the very least, axes that expand around the image in the GUI so that the image stops shrinking. I've made the background black to match the default so you at least can't see it moving, but you still see the circle shrinking and expanding. Is there a way to fix this?

Accepted Answer

Image Analyst
Image Analyst on 4 Apr 2013
You're going to have to use the 'crop' option of imrotate. Then you'll need to have a mask of where the circle is in the image. For example you can use roipoly() and poly2mask() to create such a mask. Then to paste the rotated image onto a background image you'll do something like this (untested):
imshow(wheelImage); % Show original image.
wheelImage = imrotate(wheelImage, theAngle, 'crop');
imshow(wheelImage); % Show rotated version of it.
wheelMask = roipoly(); % user defines wheel location
% Paste wheel image inside polygon onto finalImage.
finalImage(wheelMask) = rotatedWheelImage(wheelMask);
imshow(finalImage); % Show final image with rotated wheel pasted on.
That should do it.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!