图像算法---Image Deformation Using Moving Least Squares

原文地址:http://vision.gel.ulaval.ca/~jflalonde/cours/4105/h14/tps/results/project/jingweicao/index.html

Final Project: Image Deformation Using Moving Least Squares

Jingwei Cao

Project Description

In this project, I implemented the paper "Image deformation using moving least square" which is proposed by Scott Schaefer. This method consists of three type of deformation:affine deformation,similarity deformation and rigid deformation. And it also use both controlling point sets and controlling line segment sets to specify the morph.

Part1: Moving Least Squares Deformation

The MLS (Moving Least Squares) Deformation is used to find the best transformation function  f that maps  p  to  q p  is a set of controlled handles and  q  is the deformed positions of the controlled handles. The function  f(v)  needs to satisfy three conditions:(1) Interpolation: The handles  p  should map directly to  q  under deformation (i.e. f(pi)=qi )(2) Smoothness: f should produce smooth deformations (3)Identity: If the deformed handles  q  are the same as the  p , then  f  should be the identity function.(i.e.,  qi=pi f(v)=v )

1 Affine Deformation

Affine transform:  lv(x)=xM+T
Translation can be removed:  T=qpM
p=ΣiwipiΣiwi   q=ΣiwiqiΣiwi
We can easily get:  Iv(x)=(xp)M+q
The new cost function:
Σiwi|p^iMq^i|2  where  p^i=pip   q^i=qiq
M  could be different class of transformations
Solution: M=(Σip^Tiwip^i)1Σjwjp^Tjq^j
The deformation function:
fa(v)=ΣjAjq^j+q  
Aj=(vp)(Σip^Tiwip^i)1p^Ti
Aj can be precomputed
Contains non-uniform scaling and shear

2 Similarity Deformation

A special subset of affine transformations
Translation,Rotation,Constraints: Uniform-Scaling
Requirements:  MTM=λ2I
Define  M=(M1,M2) , where  M2=M1
Cost function (Least squares problem) still quadratic in  M
Σiwi|(p^ip^i)Mq^Ti|2 , where  (x,y)=(y,x)
Solution for matrix  M
M=1μsΣiwi(p^ip^i)(q^Ti,qi^T) , where  μs=Σiwip^ip^Ti
Solution for deformation function
fs(v)=Σiq^i(1μsAi)+q ,where  Ai=wi(p^ip^i)(vp(vp))T

3 Rigid Deformation

Solution for Matrix  M
M=Σi(p^ip^i)(q^Ti,qi^T)(Σiwiq^ip^Ti)2+(Σiwiq^ip^Ti)2
Solution for deformation function
fr(v)=|vp|fr(v)|fr(v)|+q , where  fr(v)=Σiq^iAi  and  Ai  is the same as in similarity deformations.

4 Experimental Results

I do the similar experiment but with the opposite direction. The puppet leans towards right.

The author's results

My own results

Original ImageAffine DeformationSimilarity DeformationRigid Deformation

Some interesting result

MonalisaDeformed Monalisa
GirrafeDeformed Girrafe

Generally speaking, the MLS image deformation using controlled points produces the result as I have expected. The rigid deformation can produce the most realistic result compared with other methods in my implementation but with the lowest speed.

Part2: Deformation with Line Segments

Handles are control curves instead of control points
Cost function
Σi10wi(t)|pi(t)M+Tqi(t)|2  and  wi(t)=|pi(t)||pi(t)v|2α
T still can be removed
T=qpM
T=qpM
Σi10wi(t)|p^i(t)Mq^i(t)|2
where  p^i(t)=pi(t)p  and  q^i(t)=qi(t)q

1 Affine Lines

Represent line segments  p^i(t) , q^i(t)  as matrix products
p^i(t)=(1t,t)(a^ib^i)  and  q^i(t)=(1t,t)(c^id^i)
Cost function
Σi10|(1t,t)((a^ib^i)M(c^id^i))|2
Minimizer
M=(Σi(a^ib^i)TWi(a^ib^i))1Σj(a^ib^i)TWj(c^id^i)
Wi=(δ00iδ01iδ01iδ11i)  where  δ00i=10wi(t)(1t)2dt
δ01i=10wi(t)(1t)tdt  and  δ11i=10wi(t)t2dt
Deformation
fa(v)=ΣjAj(c^id^i)+q
Aj=(vp)(Σi(a^ib^i)TWi(a^ib^i))1(a^jb^j)TWj

2 Similarity Lines

Cost function
Σi10|(1t001tt00t)a^ia^ib^ib^iM(c^Tid^Ti)|2
Minimizer
M=1μsΣja^ia^ib^ib^iTWj(c^Tjd^Tjc^Tjd^Tj)
where  μs=Σia^ia^Tiδ00i+2a^ib^Tiδ01i+b^ib^Tiδ11i
Wj=δ00j0δ01j00δ00j0δ01jδ01j0δ11j00δ01j0δ11j
Deformation
fs(v)=Σj(c^j,d^j)(1μsAj)+q
μs=Σia^ia^Tiδ00i+2a^ib^Tiδ01i+b^ib^Tiδ11i
Aj=Wja^ia^ib^ib^i(vp(vp))T

3 Rigid Lines

Derive from similarity lines
μr=|Σj(a^Tja^Tjb^Tjb^Tj)Wj(c^Tjd^Tj)|
Deformation
fr(v)=|vp|fr(v)|fr(v)|+q
fr(v)=Σj(c^jd^j)Aj
Aj=Wja^ia^ib^ib^i(vp(vp))T

4 Experimental Results
Original ImageAffine Line
Similarity ImageRigid Line

Unfortunately, my implementation of line segments deformation produces some unharmonious morph on the image with some bizarre artifacts at the bottom of the image region. In the rigid line deformation, the profile of the pisa tower bends too much. I think the reason is the definition of the line segments. This is really a tricky part which will affect the results.

附上一个DEMO连接:源码连接https://github.com/cxcxcxcx/imgwarp-opencv
网页版DEMO连接http://chenxing.name/fun/imgwarp-js/
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值