matlab内置函数fitgeotrans与transformPointsForward解析

来源:互联网 发布:艾磊软件 编辑:程序博客网 时间:2024/06/03 22:06

最近研究3000fps的实现,看了网上给的一个matlab代码,里面有提到init_shape到mean_shape的对齐,里面使用了fitgeotrans和transformPointsForward两个函数。于是参考matlab help研究了一下这两个函数.

fitgeotrans函数

语法:

 tform = fitgeotrans(movingPoints,fixedPoints,transformationType)

说明:

  • movingPoints — 图像上想要移动的点的坐标,至少是两个double型2维点.
  • fixedPoints — 目标点,和上面同等规模
  • transformationType — 变换类型,包括如下几种:
transformationType Description ‘Affine’ 仿射变换 ‘NonreflectiveSimilarity’ 非反射相似变换(这个有点不懂哎) ‘Projective’ 投影变换 ‘Similarity’ 相似变换(即仿射变换中去除错切变换)

总结:
这个函数主要描述了将movingPoints(设大小为:N*2,N>=2)通过某种变换变化到fixedPoints来,最后输出了变换矩阵。tform 是一个结构体类型,里面包含了变换矩阵.

transformPointsForward函数

语法:

[x,y] = transformPointsForward(tform,u,v)X = transformPointsForward(tform,U)

说明:
tform为变换矩阵. u,v分别代表你要变换的点的x,y序列。u,v必须维数相同.变换后输出了对应的x,y。
而第二个函数,U包含了[u,v],X=[x,y]。
注意:
什么是前置变换呢?
即: X=U*tform

两个例子

例1

theta = 10;tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1])[X,Y] = transformPointsForward(tform,5,10)

结果:
tform =

affine2d with properties:

             T: [3x3 double]Dimensionality: 2

其中

而X=6.6605 , Y=8.9798 。
具体计算方法是:

[6.66058.97981]=[5101]0.9848077530122080.17364817766693000.1736481776669300.9848077530122080001

例2

I = checkerboard; %创建棋盘图J = imrotate(I,30); %逆时针绕中心旋转30度imshowpair(I,J,'montage') %将两图并排放在一起

fixedPoints  = [11 11; 41 71];movingPoints = [14 44; 70 81];
tform = fitgeotrans(movingPoints,fixedPoints,'NonreflectiveSimilarity');
Jregistered = imwarp(J,tform,'OutputView',imref2d(size(I))); %应用变换,将图像旋转falsecolorOverlay = imfuse(I,Jregistered); %图形融合figure, imshow(falsecolorOverlay,'InitialMagnification','fit');

参考文献

基于空间几何变换的人脸对齐(Matlab内置函数)

0 0
原创粉丝点击