Plot a figure in which there is an image that moves and rotates
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Image Analyst
el 23 de Nov. de 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 comentarios
Image Analyst
el 23 de Nov. de 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);
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!