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

13 Ansichten (letzte 30 Tage)
Mahdi
Mahdi am 23 Nov. 2014
Kommentiert: Image Analyst am 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?

Antworten (1)

Image Analyst
Image Analyst am 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 Kommentare
Mahdi
Mahdi am 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 am 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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by