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!