Shifting an image vertically

25 visualizaciones (últimos 30 días)
Meghan Holland
Meghan Holland el 19 de Nov. de 2020
Editada: David Hill el 19 de Nov. de 2020
Hi, I need help shifting an image vertically by 100 pixels (does not matter if up or down). I also need to shift it horizontally by 240 pixels, but have already done that in a separate function, now I'm just trying to combine whatever code for the vertical shift I need with the code for the horizontal shift I already have. This is currently my code (yes I know it looks weird but this is how it's supposed to be done): edit: please see matlab code below, found code for a vertical shift
X=imread('photo1.jpg');
X_double=double(X);
X_gray = 0.3*X_double(:,:,1) + 0.3*X_double(:,:,2) + 0.3*X_double(:,:,3);
imagesc(uint8(X_gray))
colormap('gray')
[m,n]=size(X1);
r=240;
E=eye(n);
T=zeros(n,n);
T(:,1:r)=E(:,n-(r-1):n);
T(:,r+1:n)=E(:,1:n-r);
X_shift=X1*T;
imagesc(uint8(X_shift));
colormap('gray');
spy(T);
%found the code for a vertical shift, cannot figure out how to combine it with the horizontal shift for it to do both when ran
[m,n] = size(X_gray);
r = 50;
E = eye(m);
T = zeros(m);
% fill in the first r rows of T with the last r rows of E
T(1:r,:) = E(m-(r-1):m,:);
% fill in the rest of T with the first part of E
T(r+1:m,:) = E(1:m-r,:);
X_shift = T*X_gray
imagesc(uint8(X_shift));
colormap('gray');

Respuestas (1)

David Hill
David Hill el 19 de Nov. de 2020
Editada: David Hill el 19 de Nov. de 2020
circshift(image,100,1);%Do you want to circular shift the image up/down by 100 pixels?
image(1:end-99,:,:);%Or just truncate 100 pixels off?
  2 comentarios
Meghan Holland
Meghan Holland el 19 de Nov. de 2020
It's like cutting 100 pixels of the image (whether from the top or bottom) and moving in to the top or bottom, and shifting the rest of the image to fill in the blank space the cut left behind.
David Hill
David Hill el 19 de Nov. de 2020
Editada: David Hill el 19 de Nov. de 2020
The circshift should work
circshift(image,100,1);%shifts down
circshift(image,-100,1);%shifts up

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by