广发景明中短债c:用 C++ 实现散景模糊(bokeh blur)

关于广发景明中短债c的问题,在bokeh blur中经常遇到, 我们想在图像上执行散景模糊。我试图测试下面的一些代码,但无法在亮点上获得混乱的圈子。

我们想在图像上执行散景模糊。我试图测试的一些代码,但无法在亮点上获得混乱的圈子。

 void bokeh(unsigned char *Input, unsigned char *Output, int Width, int Height, int Stride, int Radius)
{
    int Channels = Stride / Width;
    int rsq = fmax(1, sqrtf(Radius));
    for (int y = 0; y < Height; y++)
    { 
        unsigned char * LinePD = Output + y*Stride;
        for (int x = 0; x < Width; x++)
        {
            unsigned int sum[3] = { 0 };
            unsigned int weightsum = 0;
            for (int ny = std::max(0, y - Radius); ny < std::min(y + Radius, Height); ny++)
            {
                const    unsigned char * sampleLine = Input + ny*Stride;
                for (int nx = std::max(0, x - Radius); nx < std::min(x + Radius, Width); nx++)
                { 
                    if (sqrtf(nx - x) + sqrtf(ny - y) < rsq)
                    {
                        const    unsigned char * sample = sampleLine + nx*Channels;
                        const    unsigned char&R = sample[0];
                        const    unsigned char&G = sample[1];
                        const    unsigned char&B = sample[2];
                        float weight = sqrtf((unsigned char)((21627 * R + 21627 * G + 21627 * B) >> 16));
                        
                        for (int c = 0; c < Channels; c++)
                        {
                            sum[c] += weight*sample[c];
                        }
                        weightsum += weight;
                    }
                }
            }
            for (int c = 0; c < Channels; c++)
            {
                LinePD[c] = ClampToByte(sum[c] / weightsum);
            } 
            LinePD += Channels;
        }
    }
}

源图像是:

source image

结果是:

result

while I expect effect is which like circular in pictures below expect effect

seems that I replace sqrtf(nx - x) + sqrtf(ny - y) < rsq with powf(nx - x, 2.0) + powf(ny - y, 2.0) < powf(Radius, 2)
and replace float weight = sqrtf((unsigned char)((21627 * R + 21627 * G + 21627 * B) >> 16)); with float weight = (R + G + B)*1.0f/3.0f; I could get enter image description here bokeh blur effect, so how to set the weight to by brightness?

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(187)
Linux查看用户权限:如何使用WindowsCMD查看用户权限
上一篇
Cass绘制地形图:绘制地形图(topography drawing)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(69条)