Plot a figure in which there is an image that moves and rotates

17 次查看(过去 30 天)
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?

回答(1 个)

Image Analyst
Image Analyst 2014-11-23
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 个评论
Mahdi
Mahdi 2014-11-23
Thank you for your sincere answer. How can I get rid of that black background that is added after using imrotate?
Image Analyst
Image Analyst 2014-11-23
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by