Spectral Matting 方法的理解

《Spectral Matting》[1]是来自Anat Levin的2008年的论文,同年他的另一篇论文是《A Closed-Form Solution to Natural Image Matting》[2](我在上一篇博客中已讨论)。2018年的《Semantic Soft Segmentation》[3]也来自CSAIL.MIT,可谓一脉相承,[3]中采用[1]的 Spectral Matting 方法,将传统方法与深度学习方法有机结合在一起,实现了复杂图像上精确到头发级的像素软标注。本文着重讨论[1]的方法,后续文章也会讨论[3]。
Matting算法的典型假设是:

I i = α i F i + ( 1 α i ) B i ( 1 )

公式(1)中 I i 表示图像 I 的像素 i 上的颜色(R,G,B)矢量, F i 表示前景颜色矢量, B i 表示背景颜色矢量, α i 表示该点的透明度取值范围是 [ 0 , 1 ] I i 是前景 F i 和背景 B i 的线性组合,该方程被称为:compositing equation。
公式(1)的透明度 α 是一个标量,[1]扩展了它,让它成为了一个矢量:
α i = { α i 1 , α i 2 , , α i K } , and has constraint k = 1 K α i k = 1 I i = k = 1 K α i k F i k ( 2 )

公式(2)中像素 i 的颜色矢量是多层颜色矢量 F i k 的线性组合。以下是一个例子:
这里写图片描述
图1 (d)中展示了8个matting层对应的 α k , ( k = 1 , , 8 ) 。(c)中Alpha matte是由(d)的 α 3 , α 5 , α 7 ((d)中 α k 的序号按行顺序排列,第一行是1、2、3、4,第二行是5、6、7、8)合并而成。
α i = { α i 1 , α i 2 , , α i K } 对应每一个像素,同一维度的分量构成一层—— α k (矢量)被称为 k t h matting component,图1(d)展示的是8个matting分层所对应的matting component,理想的matting component是稀疏的,这一点从图1(d)中可以看到,其中白色部分是1,黑色部分是0,即(原文):
Each component should be either completely opaque or completely transparent over as many image pixels as possible. This means that areas of transition between the different layers are limited to a small number of pixels, and each pixel is influenced by a small number of layers.
本文[1]主要是通过谱分析(Spectral Analysis)来分析matting component α 与其对应的Laplacian Matrix的关系。

1、谱分析(Spectral Analysis)

定义:亲和度矩阵(Affinity matrix) A ,它的每一项表示图像两点间的亲和度,可以是: A i j = e d i j / σ 2 ,其中 d i j 表示像素 i 和像素 j 之间的距离,比如:色彩距离(Color distance)、几何距离(Geometric distance)。根据 A 可以定义Laplacian matrix( L ),有 L = D A ,其中矩阵 D 是一个对角矩阵,它的对角元素是对应的亲和矩阵同一行元素的和,即: D i j = j A i j 。由上, L 是一个半正定(Semi-positive)对称矩阵。
假设:在理想情况下, A 能够恰好捕抓到在图片中不同连接件(Connected component)像素之间的关系,其实就是说在亲和度矩阵 A 上,可以看到像素之间(是否属于同一连接件)的关系。我们定义一个示性矢量 m C ,它的每一个元素是:

m i C = { 1 i C 0 i C ( 3 )

m C 对应一个连接件 C 。所谓连接件 C ,其实是一个像素集,在此集合中的像素都在同一个连接件上,并有 C I
由于 L = D A D i j = j A i j ,因此, L m C = 0 ,即 m C L 特征值(Eigenvalue) e = 0 所对应的特征矢量(Eigenvector),也就是说,特征值0有几个特征矢量,就可以分解出多少个连接件C。假设图像 I ,由K个连接件: C 1 , C 2 , , C K 组成,则与之相应的示性矢量 m C k 相互独立,是构成 L 的零空间(Nullspace)的基。
关于以上特征值,特征矢量,【1】有一段叙述:
In real images, the affinity matrix A is rarely able to perfectly separate between the different pixel clusters. Therefore, the Laplacian L usually does not have multiple eigenvectors with zero eigenvalue. However, it has been observed that the smallest eigenvectors of L tend to be nearly constant within coherent image components. Extracting the different components from the smallest eigenvectors is known as spectral rounding.
也就是说,在真实环境下,很难得到多个0特征值对应的特征矢量,但L的最小特征值所对应的特征矢量还是能体现一些连接件的特性,比如:在连贯的image components中,最小特征矢量(the smallest eigenvectors)趋向一个常数。而这种通过the smallest eigenvectors提取不同component的方法被称为spectral rounding。
【1】为阐明连接件给出一个声明:
Claim 1
Let α 1 , , α K be the actual decomposition of the image I into k matting components. The vectors α 1 , , α K lie in the nullspace of the matting Laplacian L (given by eq. 6 with ε = 0) if every local image window w satisfies one of the following conditions:
1. A single component α k is active within w .
2. Two components α k 1 , α k 2 are active within w and the colors of the corresponding layers F k 1 , F k 2 within w lie on two different lines in RGB space.
3. Three components α k 1 , α k 2 , α k 3 are active within w , each layer F k 1 , F k 2 , F k 3 has a constant color within w , and the three colors are linearly independent.
此处要求图像的每个窗体都要满足以上三个条件之一。若满足,则matting components: α 1 , , α K ,便一定在the matting Laplacian L的Nullspace上,即是L特征值为0所对应特征矢量的线性组合。【1】文中eq.6 是L的每个元素的定义 L ( i , j )
L ( i , j ) = q | ( i , j ) w q ( δ i j 1 | w q | ( 1 + ( I i μ q ) T ( Σ q + ϵ | w q | I 3 ) 1 ( I i μ q ) ) ) ( 4 )

Claim 1详细的证明见【1】。在实际图像中,并不能总满足Claim 1,[1]中有一段补充说明:
In most real images, the assumptions of claim 1 don’t hold exactly, and thus the matting Laplacian might not have multiple eigenvectors whose eigenvalue is 0. Yet if the layers are sufficiently distinct, they are generally captured by the smallest eigenvectors of L.
接下来,仍以理想情况来讨论,即图像满足Claim 1,则根据上述结论,matting components在L的Nullspace中,于是,恢复matting components问题就转化为L的Nullspace基线性变换的问题,有:
α k = E y k E = [ e 1 , e 2 , , e K ] , y k = [ y 1 , y 2 , , y K ] T ( 5 )

公式(5)中, e 1 , e 2 , , e n 表示L的0特征值所对应的K个线性无关特征矢量。 y k 表示特征矢量线性组合的权重矢量。
我们要找的matting components应该是怎样的呢?
Recall that the matting components should sum to 1 at each image pixel, and they should be near 0 or 1 for most image pixels, since the majority of image pixels are usually opaque. Thus, we are looking for a linear transformation of the eigenvectors that would yield a set of nearly binary vectors.
α k 应该接近二进制矢量,而且在同一像素点上还有和为1的约束(公式(2))。因而我们可以得到一个优化目标:
min J ( α ) = min i , k | α i k | γ + | 1 α i k | γ , where  α k = E y k Subject to  k α i k = 1 ( 6 )

这是因为,当 α i k 等于0或1时, | α i k | γ + | 1 α i k | γ 会取最小值,以下是 γ = 0.9 时的情况。

x = np.linspace(0,1,101)
y = x**0.9+ (1-x)**0.9
plt.plot(x,y)
plt.show()

这里写图片描述
图2 公式(6)的求和项在0和1处取得最小值
由上分析,对公式(6)求最小值,将会偏好得到0-1矢量,这就可以达到我们的目的了。对于 γ ,来一段原滋原味的:

If 0 < γ < 1 is used (in our implementation γ = 0.9 ), then | α i k | γ + | 1 α i k | γ is a robust score measuring the sparsity of a matting component. Without the requirement α k = E y k the sparsity term would be minimized by binary vectors, but as the vectors α k are restricted to linear combinations of the eigenvectors they must maintain the fuzzy layer boundaries. Although we do not explicitly constrain the α values to be between 0 and 1, in practice the resulting values tend to lie in this range due to the sparsity penalty.

自此,我们得到了一个关于 α 的代价函数,可进一步通过优化方法求解。
【问题】:上面用到了“谱分析”,但什么是谱分析?可参看:http://www.lunarnai.cn/2018/02/04/spectral-graph/


参考文献:
[1]《Spectral Matting》(2008) CSMIT.MIT
[2]《A Closed-Form Solution to Natural Image Matting》(2008) CSAIL.MIT
[3]《Semantic Soft Segmentation》(2018)CSAIL.MIT

猜你喜欢

转载自blog.csdn.net/StreamRock/article/details/82384962