QQ Group: 428014259
Tencent E-mail:[email protected]
http://blog.csdn.net/dgyuanshaofeng/article/details/86619758
作者:
单位:
0 摘要
1 介绍
2 相关工作
3 随机Global Sampling Method
考虑全局采样集,考虑空间距离,考虑彩色拟合度
3.1 采样选择标准
既考虑空间距离,又考虑彩色拟合度的简单损失函数。
3.2 随机搜索算法
3.2.1 SampleMatch算法
类似PatchMatch,不过搜索空间不同。初始化,传播,随机搜索类似PatchMatch算法。
3.2.2 随机搜索的分析
3.2.3 停止准则和收敛
类似PatchMatch
3.2.4 概率视角
3.2.5 PatchMatch算法的推广
3.3 后处理
matting Laplacian或fast guided filter
4 实验结果
将Global Sampling Matting方法跟Robust Matting[2]、Improved Color Matting[3]、Shared Matting[4]三种方法进行对比。
采样质量的比较:如图1、6、7、8所示,Global Sampling Matting和Shared Matting的效果差不多,但是如果采样集合里面包含未知像素的话,Shared Matting的效果会在局部上显得较差,而Global Sampling Matting的效果不会在局部上有缺陷。论文[1]的图9显示Global Sampling Matting的alpha matte的SAD分数为23.2,Shared Matting的alpha matte的SAD分数为23.6,而两者的foreground×alpha matte的SAD分数分别为10.2和10.8。因此,两者的效果确实是差不多的。为什么Shared Matting会差,原因在于其依赖trimap的topology拓扑结构,也就是ray-based的采样策略存在问题。另外,Shared Matting的损失函数比较复杂,至少具有6个参数,而Global Sampling Matting仅仅具有1个参数。
后处理的比较:论文[1]的图10显示对alpha matte进行滤波后,Global Sampling Matting和Shared Matting的alpha matte的SAD分数分别为17.9和18.4(采用matting Laplacian)或18.8和19.9(采用guided filter)。这里暗示,guided filter在准确上,是不如matting Laplacian的,但是其速度较快。【如果要制作深度学习模型的训练数据,那么考虑耗时的方法进行alpha matte估计?】论文[1]的图12显示,在alphamatting网站上进行评估,按照SAD,Shared Matting好于Global Sampling Matting(使用了trimap expansion和细心调参),按照MSE,Global Sampling Matting好于Shared Matting。
基于引导滤波的Global Sampling Matting排名SAD 5th,MSE 6th,好于实时的Shared Matting,SAD 6th,MSE 8th。
运行时间:仅仅计算采样时间,G耗时170秒,S耗时220。S的GPU版本可以实时,kaiming推测G的GPU版本也可以实时。
局限:如果解决不了color ambiguity,那么G可能会失败。那就是一个未知像素可以被假的前景后景合成得到。
5 讨论和结论
1、代价函数考虑彩色color和空间space
2、推广PatchMatch算法(在图像空间上进行匹配),在特征空间上进行匹配,形成新算法SampleMatch算法
实践
根据GitHub上面的一个C++代码,在alphamatting数据集的测试集上,对kaiming提出的算法进行测试。
1、下载代码,把cpp和h文件放在一起
git clone https://github.com/atilimcetin/global-matting
git clone https://github.com/atilimcetin/guided-filter
2、把给出的example写成一个cpp文件,命名为demo.cpp,然后把image和trimap准备好
#include "globalmatting.h"
// you can get the guided filter implementation
// from https://github.com/atilimcetin/guided-filter
#include "guidedfilter.h"
int main()
{
cv::Mat image = cv::imread("GT04-image.png", CV_LOAD_IMAGE_COLOR);
cv::Mat trimap = cv::imread("GT04-trimap.png", CV_LOAD_IMAGE_GRAYSCALE);
// (optional) exploit the affinity of neighboring pixels to reduce the
// size of the unknown region. please refer to the paper
// 'Shared Sampling for Real-Time Alpha Matting'.
expansionOfKnownRegions(image, trimap, 9);
cv::Mat foreground, alpha;
globalMatting(image, trimap, foreground, alpha);
// filter the result with fast guided filter
alpha = guidedFilter(image, alpha, 10, 1e-5);
for (int x = 0; x < trimap.cols; ++x)
for (int y = 0; y < trimap.rows; ++y)
{
if (trimap.at<uchar>(y, x) == 0)
alpha.at<uchar>(y, x) = 0;
else if (trimap.at<uchar>(y, x) == 255)
alpha.at<uchar>(y, x) = 255;
}
cv::imwrite("GT04-alpha.png", alpha);
return 0;
}
3、根据下面的教程,在Ubuntu上,安装C++版本的OpenCV 3,我的Ubuntu为14.04【如果安装了anaconda,那么在~/.bashrc里面把相关路径comment掉】【我尝试过OpenCV 2是不行的】
Install OpenCV3 on Ubuntu
4、build程序【使用cmake也是可以的】
g++ -std=c++11 demo.cpp globalmatting.cpp globalmatting.h guidedfilter.cpp guidedfilter.h `pkg-config --libs --cflags opencv` -o demo
5、执行
./demo
6、结果
[1] A Global Sampling Method for Alpha Matting CVPR 2011 [paper]
[2] Optimized Color Sampling for Robust Matting CVPR 2007 [paper]
[3] Improving Color Modeling for Alpha Matting BMVC 2008 [paper]
[4] Shared Sampling for Real-Time Alpha Matting Eurographics 2010 [paper]