shifting an image vertically down.

Hi, I want to shift a picture vertically down by 50 pixels here is my code:
X=imread('photo1.jpg');
X_double=double(X);
[m,n]=size(X_double);
E=eye(n);
T=zeros(n,n);
r=50;
T(1:r,:)=E(n-(r-1):n,:);
T(r+1:n,:)=E(1:n-r,:);
X_shift=T*X_double
I'm trying to make a transformation matrix and then multiply the resulting matrix by the image matrix "X". I keep getting an error though:
"Error using , inputs must be 2-D, or at least one input must be scalar. To compute elementwise TIMES, use TIMES (.) instead."
Any help is much appreciated, thanks.

1 件のコメント

Adam
Adam 2016 年 6 月 28 日
What are you wanting to happen to the bottom 50 pixels and what is supposed to fill the 50 left at the top? I don't see why you are trying to do a multiplicative transform just to shift an image.
Can't you just concatenate the image vertically with 50 rows of zeros?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 28 日

0 投票

You need to do the three color planes separately, because matrix multiplication is not defined for 3D arrays (RGB images are 3D arrays)

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 6 月 29 日

0 投票

Why not use imtranslate()???

質問済み:

2016 年 6 月 28 日

回答済み:

2016 年 6 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by