matlab内置函数fitgeotrans与transformPointsForward解析
最近研究3000fps的實(shí)現(xiàn),看了網(wǎng)上給的一個(gè)matlab代碼,里面有提到init_shape到mean_shape的對(duì)齊,里面使用了fitgeotrans和transformPointsForward兩個(gè)函數(shù)。于是參考matlab help研究了一下這兩個(gè)函數(shù).
fitgeotrans函數(shù)
語(yǔ)法:
tform = fitgeotrans(movingPoints,fixedPoints,transformationType)說(shuō)明:
- movingPoints — 圖像上想要移動(dòng)的點(diǎn)的坐標(biāo),至少是兩個(gè)double型2維點(diǎn).
- fixedPoints — 目標(biāo)點(diǎn),和上面同等規(guī)模
- transformationType — 變換類型,包括如下幾種:
| ‘Affine’ | 仿射變換 |
| ‘NonreflectiveSimilarity’ | 非反射相似變換(這個(gè)有點(diǎn)不懂哎) |
| ‘Projective’ | 投影變換 |
| ‘Similarity’ | 相似變換(即仿射變換中去除錯(cuò)切變換) |
總結(jié):
這個(gè)函數(shù)主要描述了將movingPoints(設(shè)大小為:N*2,N>=2)通過某種變換變化到fixedPoints來(lái),最后輸出了變換矩陣。tform 是一個(gè)結(jié)構(gòu)體類型,里面包含了變換矩陣.
transformPointsForward函數(shù)
語(yǔ)法:
[x,y] = transformPointsForward(tform,u,v) X = transformPointsForward(tform,U)說(shuō)明:
tform為變換矩陣. u,v分別代表你要變換的點(diǎn)的x,y序列。u,v必須維數(shù)相同.變換后輸出了對(duì)應(yīng)的x,y。
而第二個(gè)函數(shù),U包含了[u,v],X=[x,y]。
注意:
什么是前置變換呢?
即: X=U*tform
兩個(gè)例子
例1
theta = 10; tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]) [X,Y] = transformPointsForward(tform,5,10)結(jié)果:
tform =
affine2d with properties:
T: [3x3 double] Dimensionality: 2其中
而X=6.6605 , Y=8.9798 。
具體計(jì)算方法是:
例2
I = checkerboard; %創(chuàng)建棋盤圖 J = imrotate(I,30); %逆時(shí)針繞中心旋轉(zhuǎn)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))); %應(yīng)用變換,將圖像旋轉(zhuǎn) falsecolorOverlay = imfuse(I,Jregistered); %圖形融合 figure, imshow(falsecolorOverlay,'InitialMagnification','fit');參考文獻(xiàn)
基于空間幾何變換的人臉對(duì)齊(Matlab內(nèi)置函數(shù))
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的matlab内置函数fitgeotrans与transformPointsForward解析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【C语言进阶深度学习记录】十四 C语言中
- 下一篇: matlab 配置mex 识别vs201