Moving an image up and down

I have seen a code online on how to move an image, but it keeps coming up with an error message saying
"Error using image
Color data must be numeric or logical values."
what is the color data in my code?
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');

5 Kommentare

KSSV
KSSV am 4 Jan. 2019
I suspect the image cameraman.tif is not inbuilt image.....you are using some other image...can you tell us what does which cameraman.tif shows up?
Walter Roberson
Walter Roberson am 4 Jan. 2019
cameraman.tif has been supplied with the Image Proecessing Toolbox for a long time.
KSSV
KSSV am 4 Jan. 2019
I meant to say....the one he is using is not from inbuilt...;p
Ritzy Nanda
Ritzy Nanda am 4 Jan. 2019
I have got the code to work, but the code rotates the image and doesnt make the image move up and down. How do i make the image move up and down
Once, before the loop, call imshow(nan) and assign the result to a variable, say H. Then make the axes a fixed size, and enforce this with xlim and ylim. You probably also want to axis image
Now inside your loop, do not call imshow() again. Instead, set() the CData property of H to be the new image to be displayed (such as the rotated image.) To move the image, set() the XData and YData properties of H. XData and YData are each two-element vectors. XData(1), YData(1) gives the coordinate at which to display the center of the lowest left hand corner of the image, and XData(end), YData(end) gives the coordinate at which to display the center of the upper right hand corner of the image.
Example:
for K = 1 : 10
set(H, 'XData', [K 20+K], 'YData', [20-K 40-K])
drawnow()
end
would have the image drift rightward and downward.
XData and YData are in data coordinates, so take some care about potential differences between data coordinates and pixels.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Gefragt:

am 3 Jan. 2019

Kommentiert:

am 5 Jan. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by