Denoising opencv image in C++, Video is the same. Image in the loop.

The Opencv library has build-in a powerful denoising algorithm based on non-local means. The method is based on the theory published in an article by Antoni Buades, Bartomu Coll, and Jean-Michel Morel here. The algorithm is relatively simple, but not so easy to implement. Basically, one single pixel is replaced by the average of the colors of the area around the most similar pixel. Let's say we want to replace pixel and algorithm finding the replacement in some window. It finds the most similar replacement and additionally takes a smaller window over that most similar replacement and calculates the mean value over that. 

If we have the first window of some size and the second the smaller just one pixel. We probably replace the original one with the most similar one. If the most similar one is the noise. It will be noisy. This is a great method for calculating the output image from the sequence of input images to achieve better results. The video result is also impressive. Check the results and enjoy the simple code. 

fastNlMeansDenoisingColoredMulti  opencv denoising method results

These results are from my video. The upper part of the image is the denoised frame of the video calculated from the 4 surrounded frames. Original inputs are the lower part of the image. If you check the cropped part below the results are clearly visible. No to a much-blurred image, sharp edges, and much less noise. This is exactly what we want to achieve. 

Denoising opencv noise reduction
Denoising video sample in opencv 3,1 noise reduction
Denoising opencv noise reduction

iPhone sequence of images noise reduction

I just take the input 5 images by iPhone SE held in my hands. The result will be much better with 5 images using a tripod. 

Denoising opencv noise reductionDenoising opencv noise reduction
Denoising opencv noise reduction

Denoising opencv noise reductionDenoising opencv noise reduction
ZOOM of one of the imput image

Denoising opencv noise reduction

Results of fastNl Means Denoising Colored Multimethod

Denoising opencv noise reduction

Noise reduction Zoom ot the result

Denoising opencv noise reduction

What do you think? Let me know. 

Opencv denoising (noise reduction) c++ code

There is nothing special. Fill the vector<Mat> buffer(5); buffer with input images calculate from the buffer the method based on the templateWindowSize = 12 and searchWindowSize = 48. This is it.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/photo.hpp>
#include <opencv2\videostab.hpp>
#include "opencv2/imgcodecs.hpp"
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argcchar** argv)
     vector buffer(5);
     Mat image;
     image = imread("i1.JPG", CV_LOAD_IMAGE_COLOR);
   buffer[0] = image;
   imshow("Display window", image);
   image = imread("i2.JPG", CV_LOAD_IMAGE_COLOR);
   buffer[1] = image;
   imshow("Display window", image);
   image = imread("i3.JPG", CV_LOAD_IMAGE_COLOR);
   buffer[2] = image;
   imshow("Display window", image);
  image = imread("i4.JPG", CV_LOAD_IMAGE_COLOR);
   buffer[3] = image;
   imshow("Display window", image);
   image = imread("i5.JPG", CV_LOAD_IMAGE_COLOR);
   buffer[4] = image;
   imshow("Display window", image);
   Mat img;
   int imgs_count = 5;
   fastNlMeansDenoisingColoredMulti(buffer, img, imgs_count / 2, imgs_count, 1248);
   namedWindow("Display window", WINDOW_AUTOSIZE);
   imshow("Display window", img);  
   imwrite("result.jpg", img);
   return 0;

Denoising Colored Video example

Next Post Previous Post
  • Nakamaru
    Nakamaru December 12, 2017 at 11:32 PM

    I'm using the head cascade in my project.
    บาคาร่า gclub
    คาสิโน ออนไลน์
    สมัคร Gclub โบนัส 100%
    แทงบอล มือถือ

  • trustno1
    trustno1 January 31, 2019 at 7:16 AM

    c programming snippets
    sample code - Generate a color palette

Add Comment
comment url