图像算法---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/
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!
图片变形是一种重要的图像处理技术,有许多方法可以实现。其中之一是使用移动最小二乘Moving Least Squares,简称MLS)算法。这种方法是一种采用最小二乘法进行特征点拟合和插值的图像处理技术。 MLS算法的基本思想是通过在原始图像上选取一组特征点,然后根据特征点的位置和像素值之间建立数学模型。这些特征点可以是手动选择的,也可以通过自动检测算法获得。然后,通过最小二乘法拟合特征点的位置和像素值之间的关系,得到一个变形函数,将原始图像的像素值映射到目标图像中。在目标图像中,通过对像素点进行插值,就可以得到一个变形后的图像。 MLS算法的优点之一是它能够保持原始图像的细节和结构信息。通过特征点的选择和插值过程,能够更准确地捕捉图像变形特征。另外,MLS算法也具有较好的实时性能,能够在较短的时间内完成图像变形过程。 然而,MLS算法也存在一些挑战和局限性。首先,特征点的选择对于算法的效果至关重要。过多或过少的特征点都可能导致变形效果不佳。其次,MLS算法的计算复杂度较高,特别是在处理大型图像时。此外,MLS算法在处理一些非局部变形情况下可能会导致边缘模糊或拉伸现象。 总的来说,MLS算法是一种有效的图像变形方法。它通过建立特征点和像素值之间的关系模型,实现了图像的形变效果。尽管存在一些局限性,但MLS算法在实际应用中仍具有广泛的应用前景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值