最近研究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 。
具体计算方法是:
[