MATLAB: Image shifting using for-loops

Image Processing Toolboximage shifting

Hello everybody. So I'm trying to shift an image to the right and upward, with X and Y respectively. The values of X-Y will be decalered by the user. I need 2 nested loops one to run through the rows and the second iinside of the first to run through the cols, but when i run the file nothing changes. Any tips? thanks. clear, clc, close all img = imread('dostoevsky.tif'); imshow(img); X = 10; Y = 10; image(img) [nRows, nCols] = size(img); for X = 1:nRows for Y = 1:nCols % get pixel value pixel=img(X,Y); img2(X,Y)=pixel; end end subplot(1,2,1) imshow(img) title('original image') subplot(1,2,2) imshow(img2) title('Shifted image')

Best Answer

Use imtranslate() or circshift().