shared matting原理

2020-03-11  本文已影响0人  Cat丹

几个问题:

基本流程?

  1. Expansion of Known Regions: extrapolates “known foreground" and “known background" regions of the trimap into the “unknown" regions;
  2. Sample Selection and Matte Computation: tries to identify, for each pixel in the unknown regions, the best pair of foreground and background samples. It also com- putes an alpha matte from the obtained samples;
  3. Local Smoothing: locally smooths the resulting matte while maintaining its distinct features.

如何计算alpha值?

根据当前点颜色和估计的前景背景对颜色来计算(公式2)

double SharedMatting::comalpha(Scalar c, Scalar f, Scalar b)
{
    double alpha = ((c.val[0] - b.val[0]) * (f.val[0] - b.val[0]) +
                    (c.val[1] - b.val[1]) * (f.val[1] - b.val[1]) +
                    (c.val[2] - b.val[2]) * (f.val[2] - b.val[2]))
    / ((f.val[0] - b.val[0]) * (f.val[0] - b.val[0]) +
       (f.val[1] - b.val[1]) * (f.val[1] - b.val[1]) +
       (f.val[2] - b.val[2]) * (f.val[2] - b.val[2]) + 0.0000001);
    return min(1.0, max(0.0, alpha));
}

shared体现在哪里?

优缺点?

选择前景(背景)点的标准?

如何选择最佳(前景,背景)点对?

公式4中的积分如何实现?

将积分化成加法,在x、y两个方向分别计算

double SharedMatting::energyOfPath(int i1, int j1, int i2, int j2)
{
    double ci = i2 - i1;
    double cj = j2 - j1;
    double z  = sqrt(ci * ci + cj * cj);
    
    double ei = ci / (z + 0.0000001);
    double ej = cj / (z + 0.0000001);
    
    double stepinc = min(1 / (abs(ei) + 1e-10), 1 / (abs(ej) + 1e-10));
    double result = 0;
    
    Scalar pre = LOAD_RGB_SCALAR(data, i1*step + j1*channels);
    
    int ti = i1;
    int tj = j1;
    
    for (double t = 1; ;t += stepinc)
    {
        double inci = ei * t;
        double incj = ej * t;
        int i = int(i1 + inci + 0.5);
        int j = int(j1 + incj + 0.5);
        
        double z = 1;
        
        Scalar cur = LOAD_RGB_SCALAR(data, i*step + j*channels);
        
        if (ti - i > 0 && tj - j == 0)
        {
            z = ej;
        }
        else if(ti - i == 0 && tj - j > 0)
        {
            z = ei;
        }
        
        result += ((cur.val[0] - pre.val[0]) * (cur.val[0] - pre.val[0]) +
                   (cur.val[1] - pre.val[1]) * (cur.val[1] - pre.val[1]) +
                   (cur.val[2] - pre.val[2]) * (cur.val[2] - pre.val[2])) * z;
        pre = cur;
        
        ti = i;
        tj = j;
        
        if(abs(ci) >= abs(inci) || abs(cj) >= abs(incj))
            break;
        
    }
    
    return result;
    }

参考:

上一篇 下一篇

猜你喜欢

热点阅读