Please enable Javascript to view the contents

·  ☕ 3 分钟

## 2. 算法描述

Poisson Image Editing算法[1]的基本思想是在尽可能保持原图像内部梯度的前提下，让粘贴后图像的边界值与新的背景图相同，以实现无缝粘贴的效果。从数学上讲，对于原图像$f(x,y)$，新背景$f^(x,y)$和嵌入新背景后的新图像$v(x,y)$，等价于解最优化问题：
$$\min\limits_f \iint \Omega |\nabla f-\boldsymbol v |^2 \ \ \mathrm{with}\ f|{\partial \Omega}=f^ |_{\partial \Omega}$$

$$F_f-\frac{\mathrm d}{\mathrm d x}F_{f_x}-\frac{\mathrm d}{\mathrm d y}F_{f_y}=0$$

\begin{align} &\frac{\partial F}{\partial f}=\frac{\mathrm d}{\mathrm dx}\left[\frac{\partial F}{\partial(\nabla f_x-\pmb v_x)^2}\right]+\frac{\mathrm d}{\mathrm dy}\left[\frac{\partial F}{\partial(\nabla f_y-\pmb v_y)^2}\right]\\\\ &\Rightarrow 0=\frac{\mathrm d}{\mathrm dx}[2(\nabla f_x-\pmb v_x)]+ \frac{\mathrm d}{\mathrm dy}[2(\nabla f_y-\pmb v_y)]\\\\ &\Rightarrow 0=\left(\frac{\partial ^2f}{\partial x^2}-\frac{\partial \pmb v}{\partial x}\right)+\left(\frac{\partial ^2f}{\partial y^2}-\frac{\partial \pmb v}{\partial y}\right)\\\\ &\Rightarrow \Delta f=\mathrm{div}\pmb v \end{align}

$$\Delta f= \mathrm{div} \boldsymbol v\ \ \mathrm{over}\ \Omega\ \ \mathrm{with} \ \ f|_{\partial \Omega}=f^\ast|_{\partial\Omega}$$

$$\min\limits_{f|_\Omega}\sum\limits_{<p,q>\cap \Omega\neq \emptyset}(f_p-f_q-v_{pq})^2,\mathrm{with}\ f_p=f_p^*,\forall\ p\in \partial\Omega$$

$$\forall\ p\in \Omega,\ |N_p|f_p-\sum\limits_{q\in N_p\cap \Omega} f_q=\sum\limits_{q\in N_p\cap \partial \Omega}f_p^*+\sum\limits_{q\in N_p}v_{pq}$$

$$\forall\ <p,q>,v_{pq}=g_p-g_q$$

$$\forall\ \boldsymbol{x}\in \Omega,\ \boldsymbol{v}(\boldsymbol{x})=\begin{cases} \nabla f^*(\boldsymbol{x})&\mathrm{if}\ |\nabla f^*(\boldsymbol{x})>|\nabla g(\boldsymbol{x})|,\\\\ \nabla g(\boldsymbol{x})&\mathrm{otherwise} \end{cases}$$
**扫描线算法**

## 参考文献

[1] Patrick Pérez, Michel Gangnet, Andrew Blake. Poisson image editing. Siggraph 2003.

Wenbo Chen
CG Student