OpenCV  3.4.12
Open Source Computer Vision
Functions

Functions

void cv::denoise_TVL1 (const std::vector< Mat > &observations, Mat &result, double lambda=1.0, int niters=30)
 Primal-dual algorithm is an algorithm for solving special types of variational problems (that is, finding a function to minimize some functional). As the image denoising, in particular, may be seen as the variational problem, primal-dual algorithm then can be used to perform denoising and this is exactly what is implemented. More...
 
void cv::cuda::fastNlMeansDenoising (InputArray src, OutputArray dst, float h, int search_window=21, int block_size=7, Stream &stream=Stream::Null())
 Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising with several computational optimizations. Noise expected to be a gaussian white noise. More...
 
void cv::fastNlMeansDenoising (InputArray src, OutputArray dst, float h=3, int templateWindowSize=7, int searchWindowSize=21)
 Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ with several computational optimizations. Noise expected to be a gaussian white noise. More...
 
void cv::fastNlMeansDenoising (InputArray src, OutputArray dst, const std::vector< float > &h, int templateWindowSize=7, int searchWindowSize=21, int normType=NORM_L2)
 Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ with several computational optimizations. Noise expected to be a gaussian white noise. More...
 
void cv::cuda::fastNlMeansDenoisingColored (InputArray src, OutputArray dst, float h_luminance, float photo_render, int search_window=21, int block_size=7, Stream &stream=Stream::Null())
 Modification of fastNlMeansDenoising function for colored images. More...
 
void cv::fastNlMeansDenoisingColored (InputArray src, OutputArray dst, float h=3, float hColor=3, int templateWindowSize=7, int searchWindowSize=21)
 Modification of fastNlMeansDenoising function for colored images. More...
 
void cv::fastNlMeansDenoisingColoredMulti (InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, float h=3, float hColor=3, int templateWindowSize=7, int searchWindowSize=21)
 Modification of fastNlMeansDenoisingMulti function for colored images sequences. More...
 
void cv::fastNlMeansDenoisingMulti (InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, float h=3, int templateWindowSize=7, int searchWindowSize=21)
 Modification of fastNlMeansDenoising function for images sequence where consecutive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394 More...
 
void cv::fastNlMeansDenoisingMulti (InputArrayOfArrays srcImgs, OutputArray dst, int imgToDenoiseIndex, int temporalWindowSize, const std::vector< float > &h, int templateWindowSize=7, int searchWindowSize=21, int normType=NORM_L2)
 Modification of fastNlMeansDenoising function for images sequence where consecutive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394 More...
 
void cv::cuda::nonLocalMeans (InputArray src, OutputArray dst, float h, int search_window=21, int block_size=7, int borderMode=BORDER_DEFAULT, Stream &stream=Stream::Null())
 Performs pure non local means denoising without any simplification, and thus it is not fast. More...
 

Detailed Description

Function Documentation

◆ denoise_TVL1()

void cv::denoise_TVL1 ( const std::vector< Mat > &  observations,
Mat result,
double  lambda = 1.0,
int  niters = 30 
)
Python:
None=cv.denoise_TVL1(observations, result[, lambda[, niters]])

#include <opencv2/photo.hpp>

Primal-dual algorithm is an algorithm for solving special types of variational problems (that is, finding a function to minimize some functional). As the image denoising, in particular, may be seen as the variational problem, primal-dual algorithm then can be used to perform denoising and this is exactly what is implemented.

It should be noted, that this implementation was taken from the July 2013 blog entry [153] , which also contained (slightly more general) ready-to-use source code on Python. Subsequently, that code was rewritten on C++ with the usage of openCV by Vadim Pisarevsky at the end of July 2013 and finally it was slightly adapted by later authors.

Although the thorough discussion and justification of the algorithm involved may be found in [35], it might make sense to skim over it here, following [153] . To begin with, we consider the 1-byte gray-level images as the functions from the rectangular domain of pixels (it may be seen as set \(\left\{(x,y)\in\mathbb{N}\times\mathbb{N}\mid 1\leq x\leq n,\;1\leq y\leq m\right\}\) for some \(m,\;n\in\mathbb{N}\)) into \(\{0,1,\dots,255\}\). We shall denote the noised images as \(f_i\) and with this view, given some image \(x\) of the same size, we may measure how bad it is by the formula

\[\left\|\left\|\nabla x\right\|\right\| + \lambda\sum_i\left\|\left\|x-f_i\right\|\right\|\]

\(\|\|\cdot\|\|\) here denotes \(L_2\)-norm and as you see, the first addend states that we want our image to be smooth (ideally, having zero gradient, thus being constant) and the second states that we want our result to be close to the observations we've got. If we treat \(x\) as a function, this is exactly the functional what we seek to minimize and here the Primal-Dual algorithm comes into play.

Parameters
observationsThis array should contain one or more noised versions of the image that is to be restored.
resultHere the denoised image will be stored. There is no need to do pre-allocation of storage space, as it will be automatically allocated, if necessary.
lambdaCorresponds to \(\lambda\) in the formulas above. As it is enlarged, the smooth (blurred) images are treated more favorably than detailed (but maybe more noised) ones. Roughly speaking, as it becomes smaller, the result will be more blur but more sever outliers will be removed.
nitersNumber of iterations that the algorithm will run. Of course, as more iterations as better, but it is hard to quantitatively refine this statement, so just use the default and increase it if the results are poor.

◆ fastNlMeansDenoising() [1/3]

void cv::cuda::fastNlMeansDenoising ( InputArray  src,
OutputArray  dst,
float  h,
int  search_window = 21,
int  block_size = 7,
Stream stream = Stream::Null() 
)

#include <opencv2/photo/cuda.hpp>

Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising with several computational optimizations. Noise expected to be a gaussian white noise.

Parameters
srcInput 8-bit 1-channel, 2-channel or 3-channel image.
dstOutput image with the same size and type as src .
hParameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
search_windowSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels
block_sizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
streamStream for the asynchronous invocations.

This function expected to be applied to grayscale images. For colored images look at FastNonLocalMeansDenoising::labMethod.

See also
fastNlMeansDenoising

◆ fastNlMeansDenoising() [2/3]

void cv::fastNlMeansDenoising ( InputArray  src,
OutputArray  dst,
float  h = 3,
int  templateWindowSize = 7,
int  searchWindowSize = 21 
)
Python:
dst=cv.fastNlMeansDenoising(src[, dst[, h[, templateWindowSize[, searchWindowSize]]]])
dst=cv.fastNlMeansDenoising(src, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])

#include <opencv2/photo.hpp>

Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ with several computational optimizations. Noise expected to be a gaussian white noise.

Parameters
srcInput 8-bit 1-channel, 2-channel, 3-channel or 4-channel image.
dstOutput image with the same size and type as src .
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hParameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise

This function expected to be applied to grayscale images. For colored images look at fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting image to CIELAB colorspace and then separately denoise L and AB components with different h parameter.

◆ fastNlMeansDenoising() [3/3]

void cv::fastNlMeansDenoising ( InputArray  src,
OutputArray  dst,
const std::vector< float > &  h,
int  templateWindowSize = 7,
int  searchWindowSize = 21,
int  normType = NORM_L2 
)
Python:
dst=cv.fastNlMeansDenoising(src[, dst[, h[, templateWindowSize[, searchWindowSize]]]])
dst=cv.fastNlMeansDenoising(src, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])

#include <opencv2/photo.hpp>

Perform image denoising using Non-local Means Denoising algorithm http://www.ipol.im/pub/algo/bcm_non_local_means_denoising/ with several computational optimizations. Noise expected to be a gaussian white noise.

Parameters
srcInput 8-bit or 16-bit (only with NORM_L1) 1-channel, 2-channel, 3-channel or 4-channel image.
dstOutput image with the same size and type as src .
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hArray of parameters regulating filter strength, either one parameter applied to all channels or one per channel in dst. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
normTypeType of norm used for weight calculation. Can be either NORM_L2 or NORM_L1

This function expected to be applied to grayscale images. For colored images look at fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting image to CIELAB colorspace and then separately denoise L and AB components with different h parameter.

◆ fastNlMeansDenoisingColored() [1/2]

void cv::cuda::fastNlMeansDenoisingColored ( InputArray  src,
OutputArray  dst,
float  h_luminance,
float  photo_render,
int  search_window = 21,
int  block_size = 7,
Stream stream = Stream::Null() 
)

#include <opencv2/photo/cuda.hpp>

Modification of fastNlMeansDenoising function for colored images.

Parameters
srcInput 8-bit 3-channel image.
dstOutput image with the same size and type as src .
h_luminanceParameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
photo_renderfloat The same as h but for color components. For most images value equals 10 will be enough to remove colored noise and do not distort colors
search_windowSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater search_window - greater denoising time. Recommended value 21 pixels
block_sizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
streamStream for the asynchronous invocations.

The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using FastNonLocalMeansDenoising::simpleMethod function.

See also
fastNlMeansDenoisingColored

◆ fastNlMeansDenoisingColored() [2/2]

void cv::fastNlMeansDenoisingColored ( InputArray  src,
OutputArray  dst,
float  h = 3,
float  hColor = 3,
int  templateWindowSize = 7,
int  searchWindowSize = 21 
)
Python:
dst=cv.fastNlMeansDenoisingColored(src[, dst[, h[, hColor[, templateWindowSize[, searchWindowSize]]]]])

#include <opencv2/photo.hpp>

Modification of fastNlMeansDenoising function for colored images.

Parameters
srcInput 8-bit 3-channel image.
dstOutput image with the same size and type as src .
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hParameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
hColorThe same as h but for color components. For most images value equals 10 will be enough to remove colored noise and do not distort colors

The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using fastNlMeansDenoising function.

◆ fastNlMeansDenoisingColoredMulti()

void cv::fastNlMeansDenoisingColoredMulti ( InputArrayOfArrays  srcImgs,
OutputArray  dst,
int  imgToDenoiseIndex,
int  temporalWindowSize,
float  h = 3,
float  hColor = 3,
int  templateWindowSize = 7,
int  searchWindowSize = 21 
)
Python:
dst=cv.fastNlMeansDenoisingColoredMulti(srcImgs, imgToDenoiseIndex, temporalWindowSize[, dst[, h[, hColor[, templateWindowSize[, searchWindowSize]]]]])

#include <opencv2/photo.hpp>

Modification of fastNlMeansDenoisingMulti function for colored images sequences.

Parameters
srcImgsInput 8-bit 3-channel images sequence. All images should have the same type and size.
imgToDenoiseIndexTarget image to denoise index in srcImgs sequence
temporalWindowSizeNumber of surrounding images to use for target image denoising. Should be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise srcImgs[imgToDenoiseIndex] image.
dstOutput image with the same size and type as srcImgs images.
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hParameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise.
hColorThe same as h but for color components.

The function converts images to CIELAB colorspace and then separately denoise L and AB components with given h parameters using fastNlMeansDenoisingMulti function.

◆ fastNlMeansDenoisingMulti() [1/2]

void cv::fastNlMeansDenoisingMulti ( InputArrayOfArrays  srcImgs,
OutputArray  dst,
int  imgToDenoiseIndex,
int  temporalWindowSize,
float  h = 3,
int  templateWindowSize = 7,
int  searchWindowSize = 21 
)
Python:
dst=cv.fastNlMeansDenoisingMulti(srcImgs, imgToDenoiseIndex, temporalWindowSize[, dst[, h[, templateWindowSize[, searchWindowSize]]]])
dst=cv.fastNlMeansDenoisingMulti(srcImgs, imgToDenoiseIndex, temporalWindowSize, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])

#include <opencv2/photo.hpp>

Modification of fastNlMeansDenoising function for images sequence where consecutive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394

Parameters
srcImgsInput 8-bit 1-channel, 2-channel, 3-channel or 4-channel images sequence. All images should have the same type and size.
imgToDenoiseIndexTarget image to denoise index in srcImgs sequence
temporalWindowSizeNumber of surrounding images to use for target image denoising. Should be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise srcImgs[imgToDenoiseIndex] image.
dstOutput image with the same size and type as srcImgs images.
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hParameter regulating filter strength. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise

◆ fastNlMeansDenoisingMulti() [2/2]

void cv::fastNlMeansDenoisingMulti ( InputArrayOfArrays  srcImgs,
OutputArray  dst,
int  imgToDenoiseIndex,
int  temporalWindowSize,
const std::vector< float > &  h,
int  templateWindowSize = 7,
int  searchWindowSize = 21,
int  normType = NORM_L2 
)
Python:
dst=cv.fastNlMeansDenoisingMulti(srcImgs, imgToDenoiseIndex, temporalWindowSize[, dst[, h[, templateWindowSize[, searchWindowSize]]]])
dst=cv.fastNlMeansDenoisingMulti(srcImgs, imgToDenoiseIndex, temporalWindowSize, h[, dst[, templateWindowSize[, searchWindowSize[, normType]]]])

#include <opencv2/photo.hpp>

Modification of fastNlMeansDenoising function for images sequence where consecutive images have been captured in small period of time. For example video. This version of the function is for grayscale images or for manual manipulation with colorspaces. For more details see http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.131.6394

Parameters
srcImgsInput 8-bit or 16-bit (only with NORM_L1) 1-channel, 2-channel, 3-channel or 4-channel images sequence. All images should have the same type and size.
imgToDenoiseIndexTarget image to denoise index in srcImgs sequence
temporalWindowSizeNumber of surrounding images to use for target image denoising. Should be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise srcImgs[imgToDenoiseIndex] image.
dstOutput image with the same size and type as srcImgs images.
templateWindowSizeSize in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSizeSize in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
hArray of parameters regulating filter strength, either one parameter applied to all channels or one per channel in dst. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
normTypeType of norm used for weight calculation. Can be either NORM_L2 or NORM_L1

◆ nonLocalMeans()

void cv::cuda::nonLocalMeans ( InputArray  src,
OutputArray  dst,
float  h,
int  search_window = 21,
int  block_size = 7,
int  borderMode = BORDER_DEFAULT,
Stream stream = Stream::Null() 
)

#include <opencv2/photo/cuda.hpp>

Performs pure non local means denoising without any simplification, and thus it is not fast.

Parameters
srcSource image. Supports only CV_8UC1, CV_8UC2 and CV_8UC3.
dstDestination image.
hFilter sigma regulating filter strength for color.
search_windowSize of search window.
block_sizeSize of block used for computing weights.
borderModeBorder type. See borderInterpolate for details. BORDER_REFLECT101 , BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
streamStream for the asynchronous version.
See also
fastNlMeansDenoising