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

16 vues (au cours des 30 derniers jours)
Mahdi
Mahdi le 23 Nov 2014
Commenté : Image Analyst le 23 Nov 2014
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?

Réponses (1)

Image Analyst
Image Analyst le 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 commentaires
Mahdi
Mahdi le 23 Nov 2014
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 le 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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by