【问题标题】:Unsharp mask using NPP使用 NPP 锐化蒙版
【发布时间】:2014-03-18 06:12:08
【问题描述】:

我尝试使用 NPP 创建一个“不锐化蒙版”,但我的图像没有锐化,只是在某些区域更亮了一点。知道这段代码有什么问题吗?

    npp::loadImage("Lena.pgm", hostSrc);

    // put two copies of the image in GPU memory
    // one we'll turn into the unsharp mask                                                                                                                      
    npp::ImageNPP_8u_C1 deviceSrc(hostSrc);
    npp::ImageNPP_8u_C1 deviceUnsharpMask(hostSrc);

    // 5x5 box for mask 
    NppiSize maskSize = {5, 5};

    // create ROI based on image size and mask size                                                                                              
    NppiSize maskedROI = {deviceSrc.width() - maskSize.width + 1,
                          deviceSrc.height() - maskSize.height + 1};

    // allocate device blurred image                                                                                              
    npp::ImageNPP_8u_C1 deviceBlurred(maskedROI.width, maskedROI.height);

    NppiPoint anchor = {0, 0};

    // run box filter                                                                                                                                     
    nppiFilterBox_8u_C1R(deviceSrc.data(), deviceSrc.pitch(),
                         deviceBlurred.data(), deviceBlurred.pitch(),
                         maskedROI, maskSize, anchor);

    // subtract the masked image from the scratch image                                                                                                   
    eStatusNPP = nppiSub_8u_C1IRSfs(deviceBlurred.data(), deviceBlurred.pitch(),
                                    deviceUnsharpMask.data(), deviceUnsharpMask.pitch(),
                                    maskedROI, 1);


    // now add the mask to the src image                                                                                                                  
    eStatusNPP = nppiAdd_8u_C1IRSfs(deviceUnsharpMask.data(), deviceUnsharpMask.pitch(),
                                    deviceSrc.data(), deviceSrc.pitch(),
                                    maskedROI, 0);

    // then copy back to host and save to file

【问题讨论】:

    标签: image-processing gpu npp


    【解决方案1】:

    Unsharp Mask 的工作原理如下:

    1. 模糊原始图像 - 我们称之为 BI。
    2. 从原始图像中减去模糊图像(详细信息) - DI = OI - BI。
    3. 放大细节并将其添加到原始图像 - USMI = OI + alpha * DI。

    你确定这是你做的吗?

    这是一个参考 MATLAB 代码:

    function [ mUsmImage ] = Usm( mInputImage, usmAmount, usmRadius )
    
    gaussianKernelRadius = ceil(6 * usmRadius);
    
    mGaussianKernel = exp(-([-gaussianKernelRadius:gaussianKernelRadius] .^ 2) / (2 * usmRadius * usmRadius));
    
    mGaussianKernel = mGaussianKernel.' * mGaussianKernel;
    mGaussianKernel = mGaussianKernel / sum(mGaussianKernel(:));
    
    mBlurredLayer = imfilter(mInputImage, mGaussianKernel, 'replicate');
    
    mUsmImage = mInputImage + (usmAmount * (mInputImage - mBlurredLayer ));
    
    end
    

    该代码适用于灰度图像。 它可以很容易地用于 RGB。

    享受吧。

    【讨论】:

    • 看代码看不出来,那你为什么回答?
    • 因为我肯定看不到 Alpha 的乘法。如果你看不到它,为什么是'-1' :-)?
    • Lena.pgm 不太可能有任何 alpha,因此可以跳过该步骤。任何不是问题的实际答案的东西都应该作为评论留下。如果在一般算法描述之后有一些代码,that 将是一个答案。
    • @MarkRansom,我想你弄错了。我的 alpha 不是 Alpha 通道。这是USM的锐化量。我查看了代码,它没有应用 USM,我让用户关注 USM 是如何定义的。
    • 同样,这是一个可选步骤。您当然可以构建一个始终 alpha=1 的 USM。
    猜你喜欢
    • 2015-12-03
    • 1970-01-01
    • 2020-05-13
    • 2012-12-26
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    相关资源
    最近更新 更多