nanopyx.methods.restoration.denoising
1import numpy as np 2from ...core.transform._le_nlm_denoising import NLMDenoising 3 4 5def non_local_means_denoising(img: np.ndarray, patch_size: int = 7, patch_distance: int = 11, h: float = 0.1, sigma: float = 0.0): 6 """ 7 Apply Non-Local Means (NLM) denoising algorithm to an image. 8 9 Parameters 10 ---------- 11 img : np.ndarray 12 The input image as a 2D numpy array. 13 patch_size : int, optional 14 The size of the square patch used for denoising. Default is 7. 15 patch_distance : int, optional 16 The maximum distance between any two patches used for denoising. Default is 11. 17 h : float, optional 18 The filtering parameter controlling the degree of smoothing. Higher values increase smoothing. Default is 0.1. 19 sigma : float, optional 20 The standard deviation of the noise (if known). Default is 0.0, which means it is estimated from the image. 21 22 Returns 23 ------- 24 np.ndarray 25 The denoised image as a 2D numpy array. 26 27 Notes 28 ----- 29 The Non-Local Means algorithm denoises an image by replacing each pixel's value with an average of similar pixels in a local neighborhood. This method is particularly effective for preserving edges and fine details in images. 30 """ 31 denoiser = NLMDenoising() 32 return denoiser.run(img, patch_size=patch_size, patch_distance=patch_distance, h=h, sigma=sigma)
6def non_local_means_denoising(img: np.ndarray, patch_size: int = 7, patch_distance: int = 11, h: float = 0.1, sigma: float = 0.0): 7 """ 8 Apply Non-Local Means (NLM) denoising algorithm to an image. 9 10 Parameters 11 ---------- 12 img : np.ndarray 13 The input image as a 2D numpy array. 14 patch_size : int, optional 15 The size of the square patch used for denoising. Default is 7. 16 patch_distance : int, optional 17 The maximum distance between any two patches used for denoising. Default is 11. 18 h : float, optional 19 The filtering parameter controlling the degree of smoothing. Higher values increase smoothing. Default is 0.1. 20 sigma : float, optional 21 The standard deviation of the noise (if known). Default is 0.0, which means it is estimated from the image. 22 23 Returns 24 ------- 25 np.ndarray 26 The denoised image as a 2D numpy array. 27 28 Notes 29 ----- 30 The Non-Local Means algorithm denoises an image by replacing each pixel's value with an average of similar pixels in a local neighborhood. This method is particularly effective for preserving edges and fine details in images. 31 """ 32 denoiser = NLMDenoising() 33 return denoiser.run(img, patch_size=patch_size, patch_distance=patch_distance, h=h, sigma=sigma)
Apply Non-Local Means (NLM) denoising algorithm to an image.
Parameters
img : np.ndarray The input image as a 2D numpy array. patch_size : int, optional The size of the square patch used for denoising. Default is 7. patch_distance : int, optional The maximum distance between any two patches used for denoising. Default is 11. h : float, optional The filtering parameter controlling the degree of smoothing. Higher values increase smoothing. Default is 0.1. sigma : float, optional The standard deviation of the noise (if known). Default is 0.0, which means it is estimated from the image.
Returns
np.ndarray The denoised image as a 2D numpy array.
Notes
The Non-Local Means algorithm denoises an image by replacing each pixel's value with an average of similar pixels in a local neighborhood. This method is particularly effective for preserving edges and fine details in images.