我尝试使用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
答案 0 :(得分:-1)
钝化蒙版的工作原理如下:
你确定这是你做的吗?
这是参考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。
享受。