Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing NPP反锐化掩模_Image Processing_Gpu_Npp - Fatal编程技术网

Image processing NPP反锐化掩模

Image processing NPP反锐化掩模,image-processing,gpu,npp,Image Processing,Gpu,Npp,我试着用NPP制作一个不锐化的遮罩,但我的图像并没有锐化,只是在某些区域稍微亮了一点。知道这个代码有什么问题吗 npp::loadImage("Lena.pgm", hostSrc); // put two copies of the image in GPU memory // one we'll turn into the unsharp mask

我试着用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

反锐化遮罩的工作原理如下:

模糊原始图像-我们称之为BI。 从原始图像细节中减去模糊图像-DI=OI-BI。 放大细节并将其添加到原始图像中-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,因此可以跳过该步骤。任何不是问题的实际答案的东西都应该留作评论。如果您在一般算法描述之后有一些代码,那将是一个答案。@MarkRansom,我想您弄错了。我的阿尔法不是阿尔法通道。这是USM的锐化量。我查看了代码,但它没有应用USM,我将用户的注意力集中在如何定义USM上。同样,这是一个可选步骤。您当然可以构建一个始终alpha=1的USM。