NPP unsharp filter function not woring in Jetson xavier agx

Hi,

NPP unsharp filter function is not woring in Jetson xavier agx.
It seems to do is blur images slightly.
I’ve tried writing a minimized demo, problems remain.
Is this a bug or is my usage error?


Left is original image, right is processed image.

minimal demo code:

#define RADIUS    15
#define SIGMA     2
#define WEIGHT    100
#define THRESHOLD 0

int main() {

    cv::Mat yuv_image;
    cv::Mat orig_image = cv::imread("./lena.jpg");
    cv::cvtColor(orig_image, yuv_image, cv::COLOR_BGR2YUV_I420);

    int width = yuv_image.cols;
    int height = yuv_image.rows;
    int step = yuv_image.step;
    int size = step * height * 3 / 2;

    int scratch_buf_size = 0;
    nppiFilterUnsharpGetBufferSize_8u_C1R(RADIUS, SIGMA, &scratch_buf_size);

    Npp8u *yuv_src_dev;
    Npp8u *yuv_dst_dev;
    Npp8u *scratch_buf;
    cudaMalloc((void **)&yuv_src_dev, size);
    cudaMalloc((void **)&yuv_dst_dev, size);
    cudaMalloc((void **)&scratch_buf, scratch_buf_size);
    cudaMemcpy(yuv_src_dev, yuv_image.data, size, cudaMemcpyHostToDevice);

    nppiFilterUnsharpBorder_8u_C1R(yuv_src_dev, step, {0, 0}, 
            yuv_dst_dev, step, {width, height},
            RADIUS, SIGMA, WEIGHT, THRESHOLD,
            NPP_BORDER_REPLICATE,
            scratch_buf);

    cudaMemcpy(yuv_image.data, yuv_dst_dev, size, cudaMemcpyDeviceToHost);

    cudaFree(yuv_src_dev);
    cudaFree(yuv_dst_dev);
    cudaFree(scratch_buf);

    cv::cvtColor(yuv_image, orig_image, cv::COLOR_YUV2BGR_I420);
    cv::imwrite("./lina_unsharp.jpg", orig_image);
    return 0;
}

the attachment is code and image.
demo.zip (186.2 KB)

version info:

bsm@ubuntu:~/code/test$ cat /etc/nv_tegra_release 
# R35 (release), REVISION: 3.1, GCID: 32827747, BOARD: t186ref, EABI: aarch64, DATE: Sun Mar 19 15:19:21 UTC 2023

Hi,

Have you checked the document below?

https://docs.nvidia.com/cuda/npp/group__image__filter__unsharp__border.html#details

Do you set up the parameter with the instructions in the doc?

Thanks.

Hi,

Yes, I read the docs carefully, besides that I tried a lot of parameters.
You can try my attachment demo code, just make and run.

Thanks.

Hi,

Have you tried unsharp filter with other libraries?
If yes, could you share an example that you want to achieve with us? Like the unsharp result from OpenCV?

Thanks.

Hi,

unsharp with opencv result:


Left is original image, right is processed image.

code:

int main() {

    cv::Mat yuv_image;
    cv::Mat orig_image = cv::imread("./lena.jpg");
    cv::cvtColor(orig_image, yuv_image, cv::COLOR_BGR2YUV_I420);

    cv::Mat tmp;
    cv::GaussianBlur(yuv_image, tmp, cv::Size(RADIUS, RADIUS), SIGMA);
    cv::addWeighted(yuv_image, 1.5, tmp, -0.5, 1, yuv_image);

    cv::cvtColor(yuv_image, orig_image, cv::COLOR_YUV2BGR_I420);
    cv::imwrite("./lina_unsharp.jpg", orig_image);
    return 0;
}

If you want to test, download the attachment and make run.
opencv_demo.zip (458.7 KB)

Thanks.

Hi,

Thanks for the example.

We are double-checking this with our internal team.
Will share more information with you later.

Thanks.

Hi,

Thanks for your patience. We got some feedback from our internal team.

The function was added for a specific product several years ago.
It is not a generalized function and may not be usable for generalized purposes.

Unfortunately, we don’t have a plan to change the way it works either.
Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.