Plot a figure in which there is an image that moves and rotates
4 views (last 30 days)
Show older comments
I am going to plot a dynamic image (moving, rotating) within a MATLAB figure. How can I do that?
I know that for embedding an image in MATLAB i should use this code:
I = imread('image.jpg');
figure;
hold on;
image([-1 1],[1 -1],I);
How to draw the image by indicating its center position and its scale. How to move / rotate it?
0 Comments
Answers (1)
Image Analyst
on 23 Nov 2014
Just have a loop over angles and inside the loop call imrotate() and imshow() and drawnow.
clc;
clearvars;
close all;
workspace;
fontSize = 33;
grayImage = imread('cameraman.tif');
for angle = 0 : 10 : 360
rotatedImage = imrotate(grayImage, angle);
imshow(rotatedImage);
axis on;
caption = sprintf('Angle = %.1f', angle);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
drawnow;
pause(.5);
end
msgbox('Done with demo');
2 Comments
Image Analyst
on 23 Nov 2014
You might be able to edit imrotate.m to make the background be the same color of gray as the figure background. Or maybe you can modify the figure background to make it black. Or else just make a big "canvass" each time and paste the image in:
w = ceil(max([rows, columns]) * sqrt(2));
canvass = 128 * ones(w, w);
rotatedImage = imrotate(grayImage, angle);
binaryImage = rotatedImage > 0;
canvass(binaryImage) = rotatedImage(binaryImage);
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!