matlab图像几何变换的实现

1.水平平移

clc
I1=imread('D:/123.jpg');
gray_image=rgb2gray(I1);
[r,s]=size(gray_image);
I2=zeros(r,s);
dx=50;
dy=50;
trans=[1 0 0 ;0 1 0; dx dy 1];
for i=1:r
    for j=1:s
        temp=[i j 1];
        temp=temp*trans;
        x=temp(1,1);
        y=temp(1,2);
        if(x>=1&&x<=r)&&(y>=1&&y<=s)
            I2(x,y)=gray_image(i,j);
        end
    end
end
figure,imshow(uint8(I2));

matlab图像几何变换的实现

2.水平镜像

clc
I1=imread('D:/123.jpg');
gray_image=rgb2gray(I1);
figure,imshow(gray_image);
[r,s]=size(gray_image);
res=zeros(r,2*s);
for i=1:r
    for j=1:s
        res(i,j)=gray_image(i,j);
        res(i,2*s-j+1)=gray_image(i,j);
    end
end
figure,imshow(uint8(res));

matlab图像几何变换的实现

3.垂直镜像

clc
I=imread('D:/123.jpg');
gray_image=rgb2gray(I);
[r,s]=size(gray_image);
res=zeros(2*r,s);
for i=1:r
    for j=1:s
        res(i,j)=gray_image(i,j);
        res(2*r-i+1,j)=gray_image(i,j);
    end        
end    
figure,imshow(uint8(res));

matlab图像几何变换的实现