nppiFilterGaussBorder_8u_C1R oSrcSize and oSrcOffset parameters

86 Views Asked by At

I would like to run nppiFilterGaussBorder_8u_C1R just on a part of an image. The documentation says the following:

pSrc: Source-Image Pointer.

oSrcSize: Source image width and height in pixels relative to pSrc.

oSrcOffset: The pixel offset that pSrc points to relative to the origin of the source image.

Based on this my understanding is:

If I have a 10x10 image, and I would like to apply nppiFilterGaussBorder_8u_C1R on the TopLeft{x:2, y:2} BottomRight{x:8, y:8} area

  • pSrc should be image.ptr + 2 * 10 + 2 [an offseted pointer that points to the second row second column]
  • oSrcSize should be {10-2, 10-2} [Source image width and height in pixels relative to pSrc]
  • oSrcOffset should be {2, 2} [The pixel offset that pSrc points to relative to the origin of the source image.]
  • oSizeROI should be {8-2,8-2}

But if I calculate my parameters like this I get NPP_OUT_OFF_RANGE_ERROR in some cases (when the rect is on the bottom of the image e.g.). So most probably my understanding is not correct.

Could you please help me how I should set pSrc, oSrcSize and oSrcOffset in the mentioned example?

EDIT: Demo code:

The code uses 256x256 images instead of 10x10, the blurred area should be from TopLeft{0, 224} (inclusive) to BottomRight{256, 256} (exclusive). nppiFilterGaussBorder_8u_C1R returns NPP_OUT_OFF_RANGE_ERROR

#include <npp.h>
#include <nppi.h>
#include <istream>

int main() { 
    Npp8u* cudaMem = nppsMalloc_8u(256 * 256);
    Npp8u* cudaMemDst = nppsMalloc_8u(256 * 256);

    if(cudaMem == nullptr)
    {
        throw std::runtime_error("Error malloc");
    }

    if(cudaMemDst == nullptr)
    {
        throw std::runtime_error("Error malloc dst");
    }

    if(auto const memsetRes{nppsZero_8u(cudaMem, 256 * 256)}; memsetRes != 0)
    {
        std::cerr << "nppsZero_8u failed " << memsetRes << std::endl;
    }

    if(auto const memsetRes{nppsZero_8u(cudaMemDst, 256 * 256)}; memsetRes != 0)
    {
        std::cerr << "nppsZero_8u dst failed " << memsetRes << std::endl;
    }

    NppiPoint const blurTopLeft{0, 224};       //inclusive
    NppiPoint const blurBottomRight{256, 256}; //exclusive

    //Source image width and height in pixels relative to pSrc.
    NppiSize const oSrcSize{256 - blurTopLeft.x, 256 - blurTopLeft.y};
    NppiSize const oSizeROI{blurBottomRight.x - blurTopLeft.x, blurBottomRight.y - blurTopLeft.y};

    auto const nppiError{nppiFilterGaussBorder_8u_C1R(
        cudaMem + blurTopLeft.y * 256 + blurTopLeft.x,
        256,            // pitch
        oSrcSize,       // source image width and height in pixels relative to pSrc.
        blurTopLeft,    // aka. oSrcOffset: The pixel offset that pSrc points to relative to the origin of the source image.
        cudaMemDst + blurTopLeft.y * 256 + blurTopLeft.x,
        256,            // dst pitch
        oSizeROI,
        NPP_MASK_SIZE_3_X_3, 
        NPP_BORDER_REPLICATE
    )};

    if(nppiError != 0)
    {
        // We get NPP_OUT_OFF_RANGE_ERROR
        std::cerr << "nppiFilterGaussBorder_8u_C1R failed: " << nppiError << std::endl;
    }

    nppsFree(cudaMem);
    nppsFree(cudaMemDst);
}
0

There are 0 best solutions below