• PatchMatch小详解


    最近发了两片patch match的,其实自己也是有一些一知半解的,找了一篇不知道谁的大论文看了看,又回顾了一下,下面贴我的笔记。

    The PatchMatch Algorithm

    patchmatch一开始被应用于结构化的图片编辑。

    • 是一个随机性的算法。
    • 致力于找到近似的最近领匹配。

    patchmatch的假设:

    • 邻近的像素有一样的模型参数(pin R^n)
    • 有一个cost function可以计算给定一个(p)的代价

    PatchMatch三大步:

    • 随机初始化
    • 传播
    • 随机搜索

    PatchMatch for Motion Estimation

    因为有些像素可能会被遮挡,我们需要舍弃他们的估计。有一种方法叫forward-backward consistency check.

    这个移动也不能是无限大的,在这个论文里如果大于400像素我们就舍弃。

    Motion Models

    有各种translation motion model.

    • The Translational Motion Model

    [egin{aligned} x_{2} &=x_{1}+b_{1} \ y_{2} &=y_{1}+b_{2} end{aligned} ]

    • The Affine Motion Model

    [egin{aligned} x_{2} &=a_{1} x_{1}+a_{2} y_{1}+b_{1} \ y_{2} &=a_{3} x_{1}+a_{4} y_{1}+b_{2} end{aligned} ]

    • The Projective Motion Model

    也就是个Homography.

    [omega left( egin{array}{c}{x_{2}} \ {y_{2}} \ {1}end{array} ight)=left( egin{array}{lll}{h_{1}} & {h_{2}} & {h_{3}} \ {h_{4}} & {h_{5}} & {h_{6}} \ {h_{7}} & {h_{8}} & {h_{9}}end{array} ight) left( egin{array}{l}{x_{1}} \ {y_{1}} \ {1}end{array} ight) ]

    也可以简化一下:

    [egin{aligned} x_{2} &=frac{h_{1} x_{1}+h_{2} y_{1}+h_{3}}{h_{7} x_{1}+h_{8} y_{1}+h_{9}} \ y_{2} &=frac{h_{4} x_{1}+h_{5} y_{1}+h_{6}}{h_{7} x_{1}+h_{8} y_{1}+h_{9}} end{aligned} ]

    • The Quadratic Motion Model

    [egin{array}{l}{x_{2}-x_{1}=a_{1}+a_{2} x_{1}+a_{3} y_{1}+a_{7} x_{1}^{2}+a_{8} x_{1} y_{1}} \ {y_{2}-y_{1}=a_{4}+a_{5} x_{1}+a_{6} y_{1}+a_{7} x_{1} y_{1}+a_{8} y_{1}^{2}}end{array} ]

    PatchMatch for Stereo Reconstruction

    有几个模型,比如:eipipolar constraint model, projective planar model, the slanted plane model.

    Pipeline

    有4个步骤:

    • camera calibration

    相机标定是拿内外参,也就是内参相机位姿都要知道。

    • image rectification

    简化下一步骤,因为只需要在横坐标上搜索。

    • disparity estimation (aka stereo matching)

    • depth reconstruction

    有了相机内外参和dispairty,深度很容易估计。

    1558322695040

    [Z=frac{f cdot b}{x_{1}-x_{2}}, Y=frac{y_{1} cdot Z}{f}, X=frac{x_{1} cdot Z}{f} ]

    这里(b)是baseline, disparity (d=x_1-x_2),所以((X, Y, Z))都和disparity成倒数。

    Models for Stereo Matching

    • The Epipolar Constraint Model

    [ ilde{mathbf{x}}_{2}^{ op} mathbf{F} ilde{mathbf{x}}_{1}=0 ]

    当只有x轴上的移动,也就是在rectified image的时候,(F)会退化成如下:

    [mathbf{F}=left[ egin{array}{ccc}{0} & {0} & {0} \ {0} & {0} & {-1} \ {0} & {1} & {0}end{array} ight] ]

    这样的话,(y_2=y_1)

    • The Projective Planar Model

    [egin{aligned} x_{2} &=frac{h_{1} x_{1}+h_{2} y_{1}+h_{3}}{h_{4} x_{1}+h_{5} y_{1}+h_{6}} \ y_{2} &=y_{1} end{aligned} ]

    • The Slanted Plane Model

    这个模型假设((x, y, d))和一个法向量((n_x, n_y, n_z))在一个3D平面上,这里(d)表示视差。一个穿过点(left(x_{1}, y_{1}, d_{1} ight))的平面方程如下:

    [n_{x}left(x-x_{1} ight)+n_{y}left(y-y_{1} ight)+n_{z}left(d-d_{1} ight)=0 ]

    这个公式其实挺容易理解的,从这个点发射的向量如果和法向量乘积是0,那就在这个平面上。

    那么根据上式,视差的表达式也可以很容易推导出来:

    [d=frac{n_{x} x_{1}+n_{y} y_{1}+n_{z} d_{1}}{n_{z}}-frac{n_{x}}{n_{z}} x-frac{n_{y}}{n_{z}} y ]

    代价函数 Cost Function

    公式:

    [egin{aligned} mathcal{C}left(mathbf{p} ; x_{1}, y_{1} ight)=sum_{delta_{x}=-m}^{m} sum_{delta_{y}=-m}^{m}left(mathcal{W}left(fleft(x_{1}, y_{1} ight), fleft(x_{1}+delta_{x}, y_{1}+delta_{y} ight) ight) ight.\ cdot & holeft(fleft(x_{1}+delta_{x}, y_{1}+delta_{y} ight), gleft(x_{1}+delta_{x}-mathcal{D}left(mathbf{p} ; x_{1}+delta_{x}, y_{1}+delta_{y} ight), y_{1}+delta_{y} ight) ight) ) end{aligned} ]

    和公式:

    [egin{aligned} mathcal{C}left(mathbf{p} ; x_{2}, y_{2} ight)=sum_{delta_{x}=-m}^{m} sum_{delta_{y}=-m}^{m}left(mathcal{W}left(gleft(x_{2}, y_{2} ight), gleft(x_{2}+delta_{x}, y_{2}+delta_{y} ight) ight) ight.\ & cdot holeft(gleft(x_{2}+delta_{x}, y_{2}+delta_{y} ight), fleft(x_{2}+delta_{x}+mathcal{D}left(mathbf{p} ; x_{2}+delta_{x}, y_{2}+delta_{y} ight), y_{2}+delta_{y} ight) ight) ) end{aligned} ]

    这里(m)是patch的大小,而(mathcal{W})是一个权重函数:

    [mathcal{W}left(f(x, y), fleft(x^{prime}, y^{prime} ight) ight)=exp left(-frac{left|f(x, y)-fleft(x^{prime}, y^{prime} ight) ight|_{1}}{gamma} ight) ]

    ( ho(.))函数计算像素(f(x,y))和它的投影点(g(x-d,y))不相似度:

    [egin{aligned} ho(f(x, y), g(x-d, y))=&(1-eta) cdot min left(|f(x, y)-g(x-d, y)|_{1}, au_{c o l} ight) \ &+eta cdot min left(| abla f(x, y)- abla g(x-d, y)|_{1}, au_{g r a d} ight) end{aligned} ]

    这里(eta)就是衡量两个不同项的权重参数,( abla)是计算梯度的负号。第一项是在RGB空间里的差异,这里第二项计算的是灰度梯度的绝对值差异。

    View Propagation

    除了spatial propagation(假设邻近的像素有相似的模型参数),有一个人还加了另一个假设,认为说对应点的邻近也有相似的模型参数。

    Post-Processing

    有三个步骤: 外点剔除,invalid pixels handling和weighted median filter。

    • Outlier Removal: 用forward-backward consistency check来移除被遮挡的点。
    • Invalid Pixels Handling: 在移除了遮挡的点以后,我们在这个像素的左右各找一个最近的点,然后根据邻近点的参数计算视差,然后选一个小的视差来作为它的模型参数。
    • Weighted Median Filter: 是最后作为refinement的一步,这个只会对在forward-backward consistency check失败的点来操作。
  • 相关阅读:
    EF初始化mysql数据库codefirst
    css盒子模型、文档流、相对与绝对定位、浮动与清除模型
    微信群打卡机器人XiaoV项目开源 | 蔡培培的独立博客
    关于12306Bypass-分流抢票
    剑指Offer刷题总结
    写在前面
    mysql/mongo/nginx手册整理(2021版)
    linux(centos7) 查看磁盘空间大小
    vue中axios.post的复杂参数传参不支持的解决办法
    webApi跨域Cross问题的简单解决
  • 原文地址:https://www.cnblogs.com/tweed/p/10893548.html
Copyright © 2020-2023  润新知