nanopyx.methods.restoration.denoising
1import numpy as np 2from ...core.transform._le_nlm_denoising import NLMDenoising 3 4 5def non_local_means_denoising( 6 img: np.ndarray, 7 patch_size: int = 7, 8 patch_distance: int = 11, 9 h: float = 0.1, 10 sigma: float = 0.0, 11): 12 """ 13 Apply Non-Local Means (NLM) denoising algorithm to an image. 14 15 Parameters 16 ---------- 17 img : np.ndarray 18 The input image as a 2D numpy array. 19 patch_size : int, optional 20 The size of the square patch used for denoising. Default is 7. 21 patch_distance : int, optional 22 The maximum distance between any two patches used for denoising. Default is 11. 23 h : float, optional 24 The filtering parameter controlling the degree of smoothing. Higher values increase smoothing. Default is 0.1. 25 sigma : float, optional 26 The standard deviation of the noise (if known). Default is 0.0, please estimate the value on your image with np.float32 dtype. For example, using np.std(img.astype(np.float32)). 27 28 Returns 29 ------- 30 np.ndarray 31 The denoised image as a 2D numpy array. 32 33 Notes 34 ----- 35 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. 36 """ 37 denoiser = NLMDenoising() 38 return denoiser.run( 39 img, 40 patch_size=patch_size, 41 patch_distance=patch_distance, 42 h=h, 43 sigma=sigma, 44 )
6def non_local_means_denoising( 7 img: np.ndarray, 8 patch_size: int = 7, 9 patch_distance: int = 11, 10 h: float = 0.1, 11 sigma: float = 0.0, 12): 13 """ 14 Apply Non-Local Means (NLM) denoising algorithm to an image. 15 16 Parameters 17 ---------- 18 img : np.ndarray 19 The input image as a 2D numpy array. 20 patch_size : int, optional 21 The size of the square patch used for denoising. Default is 7. 22 patch_distance : int, optional 23 The maximum distance between any two patches used for denoising. Default is 11. 24 h : float, optional 25 The filtering parameter controlling the degree of smoothing. Higher values increase smoothing. Default is 0.1. 26 sigma : float, optional 27 The standard deviation of the noise (if known). Default is 0.0, please estimate the value on your image with np.float32 dtype. For example, using np.std(img.astype(np.float32)). 28 29 Returns 30 ------- 31 np.ndarray 32 The denoised image as a 2D numpy array. 33 34 Notes 35 ----- 36 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. 37 """ 38 denoiser = NLMDenoising() 39 return denoiser.run( 40 img, 41 patch_size=patch_size, 42 patch_distance=patch_distance, 43 h=h, 44 sigma=sigma, 45 )
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, please estimate the value on your image with np.float32 dtype. For example, using np.std(img.astype(np.float32)).
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.