数字图像处理第三次上机实验.docx
- 文档编号:3726776
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:13
- 大小:936.20KB
数字图像处理第三次上机实验.docx
《数字图像处理第三次上机实验.docx》由会员分享,可在线阅读,更多相关《数字图像处理第三次上机实验.docx(13页珍藏版)》请在冰豆网上搜索。
数字图像处理第三次上机实验
电子科技大学生命科学与技术学院
标准实验报告
(实验)课程名称数字图像处理
2012-2013-第2学期
电子科技大学教务处制表
电子科技大学
实验报告
学生姓名:
学号:
指导教师:
曾东
实验地点:
沙河校区实验时间:
2014年04月18日
一、实验室名称:
主楼西206机房
二、实验名称:
图像的几何变换
三、实验学时:
2学时
四、实验原理:
五、实验目的:
1、掌握几何变换
2、掌握插值
3、理解配准的概念
六、实验内容:
(详细填写)
1、首先自己写一个对图像进行旋转和缩放的复合变换程序;
2、然后通过基于点的配准找到一个变换矩阵,以将前面变换后的图像再变换回去。
七、实验器材(设备、元器件):
八、实验步骤:
九、实验数据及结果分析:
(详细填写)(包括程序、图、结果等)
functionV=rotation(im,degree)
imm=im2double(im);
cos_d=cos(degree);
sin_d=sin(degree);
[width,height]=size(im);
R=[cos_d-sin_d0
sin_dcos_d0
001];
T=[10-width/2.0
01-height/2.0
001];
R=inv(T)*R*T;
[W,H,ws,we,hs,he]=ComputeOutImSize(im,R);
inR=inv(R);
ii=0;
fori=ws:
we%row
ii=ii+1;jj=0;
forj=hs:
he%col
jj=jj+1;
locate_r=[ij1]';
locate_s=inR*locate_r;
if(((locate_s
(1)<=1)||(locate_s
(1)>=width))||((locate_s
(2)<=1)||(locate_s
(2)>=height)))
V(ii,jj)=0;
else
V(ii,jj)=BilinearInterplate(imm,locate_s);
end
end
end
V=im2uint8(V);
function[w,h,ws,we,hs,he]=ComputeOutImSize(im,R)
[width,height]=size(im);
corner1=[001];
corner2=[width-101];
corner3=[0height-11];
corner4=[width-1height-11];
c1=R*corner1';
c2=R*corner2';
c3=R*corner3';
c4=R*corner4';
%findthenewimageboundbox
lefttopx=min(min(c1
(1),c2
(1)),min(c3
(1),c4
(1)));
lefttopy=min(min(c1
(2),c2
(2)),min(c3
(2),c4
(2)));
rightbottomx=max(max(c1
(1),c2
(1)),max(c3
(1),c4
(1)));
rightbottomy=max(max(c1
(2),c2
(2)),max(c3
(2),c4
(2)));
leftbottomx=lefttopx;
leftbottomy=2+rightbottomy;
righttopx=2+rightbottomx;
righttopy=lefttopy;
W=ceil(righttopx-leftbottomx);
H=ceil(leftbottomy-lefttopy);
w=W;
h=H;
ws=leftbottomx;
we=righttopx;
hs=lefttopy;
he=leftbottomy;
functionVixel=BilinearInterplate(im,locate_s)
[wh]=size(im);
a=locate_s
(1);b=locate_s
(2);
x=floor(a);
y=floor(b);
xx=(a-x);yy=(b-y);
p1=im(x,y)+(im(x+1,y)-im(x,y))*xx;
p2=im(x,y+1)+(im(x+1,y+1)-im(x,y+1))*xx;
Vixel=p1+(p2-p1)*yy;
functionV=DIP_zoom(im,c,d)
im=im2double(im);
[width,height]=size(im);
im2=im;
im2(width+1:
2*width-1,:
)=im2(width-1:
-1:
1,:
);
im2(:
height+1:
2*height-1)=im2(:
height-1:
-1:
1);
R=[c00
0d0
001];
R_inv=inv(R);
w_z=fix(c*width)+1;
h_z=fix(d*height)+1;
fori=1:
w_z
forj=1:
h_z
locate_z=[i,j,1]';
locate_s=R_inv*locate_z;
if((locate_s
(1)<=1)||(locate_s
(2)<=1))
V(i,j)=0;
else
V(i,j)=BilinearInterplate(im2,locate_s);
end
end
end
functionV0=linearT(im,degree,sx,sy)
imm=im2double(im);
cos_d=cos(degree);
sin_d=sin(degree);
[width,height]=size(im);
R=[cos_d-sin_d0
sin_dcos_d0
001];
T=[10-width/2.0
01-height/2.0
001];
R=inv(T)*R*T;
[W,H,ws,we,hs,he]=ComputeOutImSize(im,R);
inR=inv(R);
ii=0;
fori=ws:
we%row
ii=ii+1;jj=0;
forj=hs:
he%col
jj=jj+1;
locate_r=[ij1]';
locate_s=inR*locate_r;
if(((locate_s
(1)<=1)||(locate_s
(1)>=width))||((locate_s
(2)<=1)||(locate_s
(2)>=height)))
V(ii,jj)=0;
else
V(ii,jj)=BilinearInterplate(imm,locate_s);
end
end
end
[width,height]=size(V);
im2=V;
im2(width+1:
2*width-1,:
)=im2(width-1:
-1:
1,:
);
im2(:
height+1:
2*height-1)=im2(:
height-1:
-1:
1);
c=sy;
d=sx;
R=[c00
0d0
001];
R_inv=inv(R);
w_z=fix(c*width)+1;
h_z=fix(d*height)+1;
fori=1:
w_z
forj=1:
h_z
locate_z=[i,j,1]';
locate_s=R_inv*locate_z;
if((locate_s
(1)<=1)||(locate_s
(2)<=1))
VV(i,j)=0;
else
VV(i,j)=BilinearInterplate(im2,locate_s);
end
end
end
V0=im2uint8(VV);
1、
im=imread('lenna.bmp');
newim=linearT(im,pi/6,2,1);
imshow(im);
figure
imshow(newim);
2、
functionout=pointMatch(fim,rim,fp1,rp1,fp2,rp2,fp3,rp3);
fcenp=floor((fp1+fp2)/2);
rcenp=floor((rp1+rp2)/2);
dx1=fp1-fcenp;
dx2=fp2-fcenp;
dx3=fp3-fcenp;
dy1=rp1-rcenp;
dy2=rp2-rcenp;
dy3=rp3-rcenp;
H=dx1*dy1'+dx2*dy2'+dx3*dy3';
H=[H(1,1)H(1,2)0;H(2,1)H(2,2)0;000];
[U,S,V]=svd(H);
R=V*[100;010;00det(U*V)]*U';
imm=im2double(fim);
[width,height]=size(imm);
[W,H,ws,we,hs,he]=ComputeOutImSize(imm,R);
inR=inv(R);
ii=0;
fori=ws:
we%row
ii=ii+1;jj=0;
forj=hs:
he%col
jj=jj+1;
locate_r=[ij1]';
locate_s=inR*locate_r;
if(((locate_s
(1)<=1)||(locate_s
(1)>=width))||((locate_s
(2)<=1)||(locate_s
(2)>=height)))
V(ii,jj)=0;
else
V(ii,jj)=BilinearInterplate(imm,locate_s);
end
end
end
out=im2uint8(V);
out=rotation(out,pi);
V0=out;
%去黑边
left=0;
right=0;
top=0;
bottom=0;
forj=1:
size(V0,2)
ifmax(V0(:
j))>0
left=j;
break
end
end
forj=size(V0,2):
-1:
1
ifmax(V0(:
j))>0
right=j;
break
end
end
fori=1:
size(V0,1)
ifmax(V0(i,:
))>0
top=i;
break
end
end
fori=size(V0,1):
-1:
1
ifmax(V0(i,:
))>0
bottom=i;
break
end
end
out=V0([top:
bottom],[left:
right]);
im=imread('lenna.bmp');
imm=linearT(im,pi/3,1,1);
imshow(im),title('参考图象');
figure
imshow(imm),title('浮动图像');
rp1=[1;1];
rp2=[1;size(im,2)];
rp3=[size(im,1);1];
fp1=[1;1];
fp2=[1;1];
fp3=[1;1];
fori=1:
size(imm,1)
forj=1:
size(imm,2)
ifimm(i,j)>0
fp2=[i;j];
break
end
end
end
forj=1:
size(imm,2)
fori=1:
size(imm,1)
ifimm(i,j)>0
fp1=[i;j];
break
end
end
end
fori=size(imm,1):
-1:
1
forj=1:
size(imm,2)
ifimm(i,j)>0
fp3=[i;j];
break
end
end
end
out=pointMatch(imm,im,fp1,rp1,fp2,rp2,fp3,rp3);
figure(3),imshow(out),title('配准后图像');
十、实验结论:
(详细填写)
十一、总结及心得体会:
(详细填写)
十二、对本实验过程及方法、手段的改进建议:
报告评分:
指导教师签字:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字图像 处理 第三次 上机 实验
![提示](https://static.bdocx.com/images/bang_tan.gif)