实验四:图像几何变换(编程 报告)
一、 实验目的
(1) 学习几种常见的图像几何变换,并通过实验体会几何变换的效果;
(2) 现
掌握图像平移、剪切、缩放、旋转、镜像、错切等几何变换的算法原理及编程实
(3) 掌握matlab编程环境中基本的图像处理函数
(4) 掌握图像的复合变换
二、 涉及知识点
(1) 图像几何变换不改变图像像素的值,只改变像素所在的几何位置
(2) 图像裁剪imcrop函数,语法格式为:
B=imcrop(A);交互式用鼠标选取区域进行剪切
B=imcrop(A,[left top right bottom]);针对指定的区域[left top right bottom]进行剪切
(3) 图像缩放imresize函数,语法格式为:
(4) B = imresize(A,m,method)
(5) 这里参数method用于指定插值的方法,可选用的值为'nearest'(最邻近法),
'bilinear'(双线性插值),'bicubic'(双三次插值),默认为'nearest'。
(6) B = imresize(A,m,method)返回原图A的m倍放大的图像(m小于1时效果
是缩小)。
(7) 图像旋转imrotate函数,语法格式为:
B = imrotate(A,angle,’crop’),参数crop用于指定裁剪旋转后超出图像的部分。
三、 实验内容
(1) 将图像hehua.bmp裁剪成200X200大小
(2) 制作动画,将一幅图像逐渐向左上角平移移出图像区域,空白的地方用白色填充
(3) 利用剪切图像函数制作动画
(4) 像。
将图像分别放大1.5倍和缩小0.8倍,插值方法使用双线性插值法,分别显示图
(5) 将图像水平镜像,再顺时针旋转45度,显示旋转后的图像。
(6) 将图像分别进行水平方向30度错切,垂直方向45度错切,分别显示结果
四、 实验环境
Windows下matlab编程环境
五、 实验源代码及结果
1. f=imread('hehua.bmp');
figure;
imshow(f);
title('原图');
f2=imcrop(f,[50,50,250,250]);
figure;
imshow(uint8(f2));
title('裁剪后');
imwrite(f2,'d:/5/hehua1.bmp');
2. f=imread('hehua1.bmp');
[m,n,x]=size(f);
f=double(f);
for i=1:10
mx=10*i;
my=10*i;
g=zeros(m,n,x)+255;
%g(mx+1:m,my+1:n,1:x)=f(1:m-mx,1:n-my ,1:x);
g(1:m-mx,1:n-my ,1:x)=f(mx+1:m,my+1:n,1:x);
figure;
imshow(uint8(g));
end
3. f=imread('hehua1.bmp');
[m,n]=size(f);
for i=50:10:200
m=i;
n=i;
f2=imcrop(f,[n,n,m,m]);
figure;
imshow(uint8(f2));
end
4. f=imread('hehua1.bmp');
figure;
imshow(f);
title('原图');
f=double(f);
f1=imresize(f,1.5,'bilinear');
figure;
imshow(uint8(f1));
title('放大1.5倍');
f2=imresize(f,0.8,'bilinear');
figure;
imshow(uint8(f2));
title('缩小0.8倍');
5. f=imread('hehua1.bmp');
subplot(131);
imshow(f);
title('原图');
[m,n,x]=size(f);
g=zeros(m,n,x);
for i=1:m
for j=1:n
for k=1:x
g(i,j,k)=f(i,n-j+1,k);
end
end
end
subplot(132);
imshow(uint8(g));
title('水平镜像');
f2=imrotate(g,45,'crop');
subplot(133);
imshow(uint8(f2));
title('顺时针旋转45度');
6. f=imread('hehua1.bmp');
subplot(131);
imshow(f);
title('原图');
h=size(f);
f1=zeros(h(1)+round(h(2)*tan(pi/6)),h(2),h(3));
for m=1:h(1)
for n=1:h(2)
f1(m+round(n*tan(pi/6)),n,1:h(3))=f(m,n,1:h(3));
end
end
subplot(132);
imshow(uint8(f1));
title('水平30度');
f2=zeros(h(1),h(2)+round(h(2)*tan(pi/4)),h(3));
for m=1:h(1)
for n=1:h(2)
f2(m,n+round(m*tan(pi/4)),1:h(3))=f(m,n,1:h(3));
end
end
subplot(133);
imshow(uint8(f2));
title('垂直45度');
六、 心得体会
因篇幅问题不能全部显示,请点此查看更多更全内容