Image Denoise Filters using Python, PyCuda and Cuda

Hello,

for those who want to apply denoise filter to opencv images (using cv2.ImRead and therefore classical image format), i wrote some routines which could interest you.

The base routines are from Nvidia Cuda SDK example (many thanks Nvidia). I changed code to not use Tex2D and just use 3D arrays from cv2.imread (colour image) or 1D array for mono images.

There are 4 files :

  • KNN denoise filter for colour image
  • KNN denoise filter for monochrome image
  • Fast NLM denoise filter for colour image
  • Fast NLM denoise filter for monochrome image

For each program, i compare OpenCV routine (cv2.fastNlMeansDenoisingColored or cv2.fastNlMeansDenoising) to PyCuda/Cuda routine.

You can find the files here :

https://github.com/AlainPaillou/PyCuda_Denoise_Filters

I made some speed tests comparisons between OpenCV and PyCuda for colour images using a Jetson Nano :

1544*1040 pixels image :

  • OpenCV FastNLMDenoise : 0.92 seconds
  • fast NLM PyCuda : 0.17 seconds
  • KNN PyCuda : 0.068 seconds

3096*2080 pixels image :

  • OpenCV FastNLMDenoise : 2.6 seconds
  • fast NLM PyCuda : 0.67 seconds
  • KNN PyCuda : 0.25 seconds

That’s a really good improvement.

I would like to thanks again Nvidia for their work, their support and for having provided me for free a Jetson Nano to support my project (related to astronomy imaging).

If you find some improvements to those routines, i am very interested in.

Alain

Hello,

I have modified the KNN & NLM2 routines to avoid border effect error (array index out of range).

GitHub is up to date with those modifications.

I also tried those filters with a PC laptop i7-6700HQ CPU and GTX960M GPU under Windows 10 64b.

Here are the speed tests results :

1544*1040 pixels image :
Laptop PC :

  • OpenCV FastNLMDenoise : 0.32 seconds
  • fast NLM PyCuda : 0.033 seconds
  • KNN PyCuda : 0.025 seconds

Jetson Nano :

  • OpenCV FastNLMDenoise : 0.92 seconds
  • fast NLM PyCuda : 0.17 seconds
  • KNN PyCuda : 0.068 seconds

3096*2080 pixels image :
Laptop PC :

  • OpenCV FastNLMDenoise : 0.82 seconds
  • fast NLM PyCuda : 0.11 seconds
  • KNN PyCuda : 0.07 seconds

Jetson Nano :

  • OpenCV FastNLMDenoise : 2.6 seconds
  • fast NLM PyCuda : 0.67 seconds
  • KNN PyCuda : 0.25 seconds

Alain