我尝试使用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发布于 2014-06-03 05:18:47
Unsharp Mask的工作原理如下:
你确定这就是你要做的?
这是一个参考的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采用。
好好享受吧。
https://stackoverflow.com/questions/22471636
复制相似问题