Combining two codes into one?

2 ビュー (過去 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 Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by