Shifting an image using matrix manipulation.

4 Ansichten (letzte 30 Tage)
Odom Seng
Odom Seng am 30 Jun. 2016
Beantwortet: Image Analyst am 30 Jun. 2016
Hi, I have a codeline that shifts an image 240 pixels horizontally. I used the code from an example in my class, however they do it in grayscale and I want to keep the shifted image in the original color. What do i have to modify in order to keep the same color as the original image.
Here's the code:
if true
% code
function [] = hshift
X=imread('photo1.jpg');
X_double=double(X);
red_channel_X= X_double(:,:,1);
green_channel_X=X_double(:,:,2);
blue_channel_X=X_double(:,:,3);
X1=.3*red_channel_X+.3*green_channel_X+.4*blue_channel_X;
colormap('default')
[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('default');
end

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Jun. 2016
Simply use imtranslate().

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by