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
KSSV
2019년 1월 4일
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
2019년 1월 4일
cameraman.tif has been supplied with the Image Proecessing Toolbox for a long time.
KSSV
2019년 1월 4일
I meant to say....the one he is using is not from inbuilt...;p
Ritzy Nanda
2019년 1월 4일
Walter Roberson
2019년 1월 5일
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.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Video Formats and Interfaces에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!