Combining two codes into one?

5 次查看(过去 30 天)
Meghan Holland
Meghan Holland 2020-11-19
回答: David Hill 2020-11-19
Hi, need help combing these two codes. One shifts an image horizontally and one shifts an image vertically. Been tinkering with the codes for hours now and cannot figure out how to combine the two so they both do their respective shifts at the same time on the same image. Thank you!
%horizontal 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');
%vertical shift
[m,n] = size(X_gray);
r = 100;
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');

回答(1 个)

David Hill
David Hill 2020-11-19
It does not matter if the shifts are done sequentually.
a=circshift(circshift(image,100,1),100,2);
b=circshift(circshift(image,100,2),100,1);

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by