Combining two codes into one?
조회 수: 4 (최근 30일)
이전 댓글 표시
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');
댓글 수: 0
답변 (1개)
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!