Hi,
I’m having problem using the NPP morphological functions, namely nppiErode_8u_C1R, and nppiDilate_8u_C1R. Documentation is lacking and the samples provided with NPP do not cover the morphological operations. I’m trying to modify the box filter example to call nppiErode_8u_C1R instead however the kernel is returning a -3 error (Kernel Launch Failure). I’m trying to call erode with a 3x3 kernel and an anchor centered in the middle of the kernel as follows:
try
{
//////
// Start of sample code
//////
// if more than one command line arg, use the first arg as the filename,
// otherwise assume the filename included with the sample
std::string sFilename = "../../data/Lena.pgm";
if (argc >= 2)
sFilename = argv[1];
std::string sResultFilename = sFilename;
std::string::size_type dot = sResultFilename.rfind('.');
if (dot != std::string::npos) sResultFilename = sResultFilename.substr(0, dot);
sResultFilename += "_boxFilter.pgm";
if (argc >= 3)
sResultFilename = argv[2];
// declare a host image object for an 8-bit grayscale image
npp::ImageCPU_8u_C1 oHostSrc;
// load gray-scale image from disk
npp::loadImage(sFilename, oHostSrc);
// declara a device image and copy construct from the host image,
// i.e. upload host to device
npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc);
/////
// End Sample Code
//////
// 3x3 mask
NppiSize oMaskSize = {3, 3};
// mask... is this the correct way to initialize the mask??
Npp8u mask[9] = {1,1,1,1,1,1,1,1,1};
// ROI... the size of the input image
NppiSize oSizeROI = {oDeviceSrc.width(), oDeviceSrc.height()};
// allocate output image same as input image
npp::ImageNPP_8u_C1 oDeviceDst(oSizeROI.width, oSizeROI.height);
// set anchor point inside the mask to (1, 1)
NppiPoint oAnchor = {1, 1};
// run erode
NppStatus eStatusNPP;
eStatusNPP = nppiErode_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(), oDeviceDst.data(), oDeviceDst.pitch(), oSizeROI, mask, oMaskSize, oAnchor);
////
// Start of Sample Code
////
NPP_ASSERT(NPP_NO_ERROR == eStatusNPP);
// declare a host image for the result
npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size());
// and copy the device result data into it
oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch());
saveImage(sResultFilename, oHostDst);
std::cout << "Saved image: " << sResultFilename << std::endl;
}
catch (npp::Exception & rException)
{
std::cerr << "Program error! The following exception occurred: \n";
std::cerr << rException << std::endl;
std::cerr << "Aborting." << std::endl;
getchar();
return -1;
}
catch (...)
{
std::cerr << "Program error! An unknow type of exception occurred. \n";
std::cerr << "Aborting." << std::endl;
getchar();
return -1;
}
////
// End of Sample Code
////
Can anyone please point out what I’m doing wrong?
Thanks,
Steven