Combining two codes into one?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
David Hill
le 19 Nov 2020
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 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!