Matrix Operations Horizontal and Vertical Shifts

3 次查看(过去 30 天)
I need to shift photo1.jpg 240 pixels horizontally and 100 pixels vertically using the spy () function. How can I do this if the matrix isn't square? So far I have this code
% Read the image
img1 = imread('photo1.jpg');
% Convert it to double
img1Double = im2double(img1);
% Convert from RGB to grayscale
img1Gray = rgb2gray(img1);
figure
imshowpair(img1, img1Gray, 'montage')
img2 = imread('photo2.jpg');
% Convert it to double
img2Double = im2double(img2);
% Convert from RGB to grayscale
img2Gray = rgb2gray(img2);
figure
imshowpair(img2, img2Gray, 'montage')
  2 个评论
Setsuna Yuuki.
Setsuna Yuuki. 2020-11-15
Did you try using "imresize" to make a square image?
im = imread('image.jpg');
im = imresize(im,[drow dcolumn])
Viridiana Varela
Viridiana Varela 2020-11-15
Yes and I think it worked, but how do I display the image using the spy function?

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2020-11-15
编辑:Matt J 2020-11-15
The spy() function does not care if its input is square, but it doesn't have any relevance to shifting images. I don't know why you think it belongs here. However, shifting an image is readily accomplished using imtranslate(),
% Read the image
img1 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/414283/photo1.jpg');
% Convert it to double
imshowpair(img1, imtranslate(img1,[240,100]), 'montage')

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by