图像的平移变换

%%%%%%%%图像的平移变换
clc
clear all
im=imread('C:\Users\lhj\Desktop\lena.jpg');
dx=80; dy=80; % 平移的参数
[m n]=size(im); % 图像的尺寸
for i=1:m-dx
for j=1:n-dy
t=[i j 1]*[1 0 0;0 1 0;dx dy 1];
new(t(1),t(2))=im(i,j);
end
end
subplot(1,2,1)
imshow(im)
title(‘原始图像')

subplot(1,2,2)
imshow(new)
title(strcat(‘平移图像,dx=',num2str(dx),',dy=',num2str(dy)));



clc
clear all
im=imread('C:\Users\Administrator\Desktop\实验3-几何变换实验\lena.jpg');
[m n]=size(im); % 图像的尺寸
for i=1:m
for j=1:n
t=[i j 1]*[-1 0 0;0 1 0;m+1 0 1];
new(t(1),t(2))=im(i,j);
end
end
subplot(1,2,1)
imshow(im)
title('原始图像')

subplot(1,2,2)
imshow(new)
title(strcat('垂直镜像图像,dx=',num2str(dx),',dy=',num2str(dy)));



比例变换
clc
clear all
im=imread('C:\Users\Administrator\Desktop\实验3-几何变换实验\lena.jpg');
a=2;b=3;
[m n]=size(im); % 图像的尺寸
for i=1:m
for j=1:n
t=[i j 1]*[a 0 0;0 b 0;0 0 1];
new(t(1),t(2))=im(i,j);
end
end
subplot(1,2,1)
imshow(im)
title('原始图像')

subplot(1,2,2)
imshow(new)

图像缩放
clc
clear all
im=imread('C:\Users\Administrator\Desktop\实验3-几何变换实验\lena.jpg');
a=4;b=3;
[m n]=size(im); % 图像的尺寸

for i=1:(a*m);
for j=1:(b*n);
t=[i j 1]*[1/a 0 0;0 1/b 0;0 0 1];
t(1)=round(t(1));
t(2)=round(t(2));
if t(1)<1
t(1)=1;
end
if t(2)<1
t(2)=1;
end
if t(1)>m
t(1)=m;
end
if t(2)>n
t(2)=n;
end
new(i,j)=im(t(1),t(2));
end

end

subplot(1,2,1)
imshow(im)
title('原始图像')

subplot(1,2,2)
imshow(new)
title('变换后图像')

图像转置
clc
clear all
im=imread('C:\Users\Administrator\Desktop\实验3-几何变换实验\lena.jpg');

[m n]=size(im); % 图像的尺寸



for i=1:m
for j=1:n
t=[i j 1]*[0 1 0;1 0 0;0 0 1];
new(t(1),t(2))=im(i,j);
end
end

subplot(1,2,1)
imshow(im)
title('原始图像')

subplot(1,2,2)
imshow(new)
title('变换后图像')

相关文档
最新文档