ztong上机3

  

二、实验名称:数字图像处理matlab上机

三、实验学时:2学时

四、实验目的:(详细填写)

  • 掌握几何变换
  • 掌握插值
  • 理解配准的概念

五.实验内容

  • (1)首先自己写一个对图像进行旋转和缩放的复合变换程序;
  • (2)然后通过基于点的配准找到一个变换矩阵,以将前面变换后的图像再变换回去。

六、实验器材(设备、元器件):

硬件:计算机 软件:windows XP ,matlab7.0

七、实验数据及结果分析:

内容一程序:

   1:  
   2: function out = LinearT( 
   3: In,theta,sx, sy) 
   4: im 
   5: = imread(In); 
   6: degree = theta; 
   7: imm = im2double(im); 
   8: cos_d = cos(degree); 
   9: sin_d = sin(degree);  
  10: [width, height] = size(im);  
  11: R 
  12: = [cos_d -sin_d 0 
  13: sin_d cos_d 0 
  14: 0 
  15: 0 1]; 
  16: T 
  17: = [1 0 -width/2.0 
  18: 0 
  19: 1 -height/2.0 
  20: 0 
  21: 0 1]; 
  22: S=[sx,0,0; 
  23: 0,sy,0; 
  24: 0,0,1];  
  25: R=inv(T)*S*R*T;  
  26: [W, H, ws, we, hs, he] = 
  27: ComputeOutImSize(im, R); 
  28:  
  29: inR = inv(R); 
  30: ii=0; 
  31:  
  32: for i = ws:we%row 
  33: ii=ii+1; jj=0; 
  34: for j = hs:he%col 
  35: jj=jj+1; 
  36: locate_r = [i j 1]'; 
  37: locate_s = inR*locate_r; 
  38: if(((locate_s(1)<=1)||(locate_s(1)>=width))||((locate_s(2)<=1)||(locate_s(2)>=height))) 
  39: V(ii,jj) = 0; 
  40: else 
  41: V(ii,jj) = 
  42: BilinearInterplate(imm,locate_s); 
  43:  
  44: end 
  45: end 
  46: end 
  47:  
  48: out= im2uint8(V); 
  49: end 
  50:  
  51: 调用程序 
  52: In='pre.bmp'; 
  53:  
  54: theta=pi/8; 
  55: sx=2; 
  56:  
  57: sy=4; 
  58:  
  59: out = LinearT( In,theta,sx, 
  60: sy); 
  61: imshow(out) 
  62:  

原始图像

   1

处理后的图像

   2

  

  

内容二程序

   1:  
   2: s=1; 
   3:  
   4: f1=imread('pre.bmp'); 
   5:  
   6: f2=imread('flop.bmp'); 
   7:  
   8: figure(1) 
   9: subplot(121),imshow(f1) 
  10: subplot(122),imshow(f2) 
  11: N=4; 
  12: imtool(f2) 
  13: [w1,h1]=size(f1); 
  14: [w2,h2]=size(f2); 
  15: a=[0 0]';b=[w1-1 0]';c=[0 h1-1]';d=[w1-1 
  16: h1-1]'; 
  17: a1=[4 93]';b1=[224 1]';c1=[113 
  18: 359]';d1=[333 267]'; 
  19: x=[a b c d]; 
  20: y=[a1 b1 c1 d1]; 
  21: H=zeros(2); 
  22: xmean=[sum(x(1,:))/N;sum(x(2,:))/N]; 
  23:  
  24: ymean=[sum(y(1,:))/N;sum(y(2,:))/N]; 
  25:  
  26: xx=[x(1,:)-xmean(1);x(2,:)-xmean(2)]; 
  27:  
  28: yy=[y(1,:)-ymean(1);y(2,:)-ymean(2)]; 
  29:  
  30: for i=1:N 
  31: H=H+xx(:,i)*(yy(:,i))'; 
  32: end 
  33: [U,S,V]=svd(H); 
  34: r=det(U*V); 
  35: W=[1 0;0 r]; 
  36: R=V*W*U'; 
  37: s=0; 
  38:  
  39: for i=1:N 
  40: s1=s+R*xx(:,i).*yy(:,i); 
  41: end 
  42:  
  43: for i=1:N 
  44: s2=s+R*xx(:,i).*xx(:,i); 
  45: end 
  46:  
  47: s=s1/s2; 
  48: t=xmean-s*R*ymean; 
  49: imm=im2double(f2); 
  50: ii=0; 
  51: for i 
  52: =1:w1 
  53: ii=ii+1; jj=0; 
  54: for j = 
  55: 1:h1 
  56: jj=jj+1; 
  57: SS=inv(R)*([i j]'-t); 
  58: if(((SS(1)<=1)||(SS(1)>=w2))||((SS(2)<=1)||(SS(2)>=h2))) 
  59:  
  60: S(ii,jj) = 0; 
  61: else 
  62: S(ii,jj) = BilinearInterplate(imm,SS); 
  63:  
  64: end 
  65: end 
  66:  
  67: end 
  68:  
  69: S0= 
  70: im2uint8(S); 
  71: figure(2) 
  72: imshow(S0) 
  73:  

  

  

  

八、总结及心得体会:

  • 掌握了几何变换
  • 掌握了插值
  • 理解了配准的概念

  

  

报告评分:

指导教师签字:

posted on 2014-04-25 13:24  CHEN NEHC  阅读(194)  评论(0)    收藏  举报