Matrix Operations Horizontal and Vertical Shifts
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Setsuna Yuuki.
il 15 Nov 2020
Did you try using "imresize" to make a square image?
im = imread('image.jpg');
im = imresize(im,[drow dcolumn])
Risposte (1)
Matt J
il 15 Nov 2020
Modificato: Matt J
il 15 Nov 2020
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')
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
