ImageDenoiserClassic - Classic Image Denoiser
ImageDenoiserClassic
- class aydin.it.classic.ImageDenoiserClassic(method: str = 'butterworth', main_channel: Optional[int] = None, max_voxels_for_training: Optional[int] = None, calibration_kwargs: Optional[dict] = None, blind_spots: Optional[Union[str, List[Tuple[int]]]] = None, tile_min_margin: int = 8, tile_max_margin: Optional[int] = None, max_memory_usage_ratio: float = 0.9, max_tiling_overhead: float = 0.1)[source]
Classic Image Denoiser
- add_transform(transform: aydin.it.transforms.base.ImageTransformBase, sort: bool = True)
Adds the given transform to the self.transforms_list
- Parameters
- transformImageTransformBase
- clear_transforms()
Clears the transforms list
- static load(path: str)
Returns an ‘all-batteries-included’ image translation model at a given path (folder).
- Parameters
- pathstr
path to load from.
- static parse_axes_args(batch_axes: Union[List[int], List[bool]], chan_axes: Union[List[int], List[bool]], ndim: int)
- Parameters
- batch_axesUnion[List[int], List[bool]]
- chan_axesUnion[List[int], List[bool]]
- ndimint
- save(path: str)[source]
Saves a ‘all-batteries-included’ image translation model at a given path (folder).
- Parameters
- pathstr
path to save to
- Returns
- frozen
- train(input_image, target_image=None, batch_axes=None, channel_axes=None, train_valid_ratio=0.1, callback_period=3, jinv=None)
Train to translate a given input image to a given output image. This has a lot of the machinery for batching and more…
Procedural calibration and denoising API:
Bilateral
- aydin.it.classic_denoisers.bilateral.calibrate_denoise_bilateral(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], bins: int = 10000, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the bilateral denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
Note: it seems that the bilateral filter of scikit-image is broken!
- Parameters
- image: ArrayLike
Image to calibrate denoiser for.
- bins: int
Number of discrete values for Gaussian weights of color filtering. A larger value results in improved accuracy. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.bilateral.denoise_bilateral(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], sigma_color: Optional[float] = None, sigma_spatial: float = 1, bins: int = 10000, **kwargs)[source]
Denoises the given image using a <a href=”https://en.wikipedia.org/wiki/Bilateral_filter”>bilateral filter</a>. The bilateral filter is a edge-preserving smoothing filter that can be used for image denoising. Each pixel value is replaced by a weighted average of intensity values from nearby pixels. The weighting is inversely related to the pixel distance in space but also in the pixels value differences.
- Parameters
- imageArrayLike
Image to denoise
- sigma_colorfloat
Standard deviation for grayvalue/color distance (radiometric similarity). A larger value results in averaging of pixels with larger radiometric differences. Note, that the image will be converted using the img_as_float function and thus the standard deviation is in respect to the range
[0, 1]
. If the value isNone
the standard deviation of theimage
will be used.- sigma_spatialfloat
Standard deviation for range distance. A larger value results in averaging of pixels with larger spatial differences.
- binsint
Number of discrete values for Gaussian weights of color filtering. A larger value results in improved accuracy.
- kwargs: dict
Other parameters
- Returns
- Denoised image
BMND
- aydin.it.classic_denoisers.bmnd.calibrate_denoise_bmnd(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[Union[int, Tuple[int], str]] = None)[source]
Calibrates the BMnD denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate spectral denoiser for.
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results.
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.bmnd.denoise_bmnd(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[Union[int, Tuple[int]]] = None, block_depth: Optional[int] = None, mode: str = 'median', reconstruction_gamma: float = 0, multi_core: bool = True)[source]
Denoises the given image using the Block-Matching-nD approach. Our implementation follows the general outline of <a href=”https://en.wikipedia.org/wiki/Block-matching_and_3D_filtering”> Block-matching and 3D filtering (BM3D)</a> approaches.
Note: This is currently only usable for small images, even for moderately sized images the computation time is prohibitive. We are planning to implement a GPU version to make it more usefull.
- Parameters
- image: ArrayLike
Image to denoise
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be: ‘full’ for a single patch covering the whole image, ‘half’, ‘quarter’, or an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results.
- block_depth: int or None for default
Block depth.
- mode: str
Possible modes are: ‘median’, ‘mean’.
- threshold: float
Threshold between 0 and 1
- freq_bias_stength: float
Frequency bias: closer to zero: no bias against high frequencies, closer to one and above: stronger bias towards high-frequencies.
- freq_cutoff: float
Cutoff frequency, must be within [0, 1]. In addition
- order: float
Filter order, typically an integer above 1.
- reconstruction_gamma: float
Patch reconstruction parameter
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery.
- Returns
- Denoised image
Butterworth
- aydin.it.classic_denoisers.butterworth.calibrate_denoise_butterworth(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], mode: str = 'full', axes: Optional[Tuple[int, ...]] = None, other_filters: bool = False, min_padding: int = 2, max_padding: int = 32, min_freq: float = 1e-09, max_freq: float = 1.0, frequency_tolerance: float = 0.05, min_order: float = 1.0, max_order: float = 8.0, crop_size_in_voxels: Optional[int] = 1000000, optimiser: str = 'fast', max_num_evaluations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', multi_core: bool = True, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Butterworth denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate Butterworth denoiser for.
- mode: str
Possible modes are: ‘isotropic’ for isotropic, meaning only one frequency cut-off is calibrated for all axes , ‘z-yx’ (or ‘xy-z’) for 3D stacks where the cut-off frequency for the x and y axes is the same but different for the z axis, ‘t-z-yx’ (or ‘xy-z-t’) for 3D+t timelapse where the cut-off frequency for the x and y axes is the same but different for the z and t axis, and ‘full’ for which all frequency cut-offs are different. Use ‘z-yx’ or ‘t-z-yx’ for axes are ordered as: t, z, y and then x which is the default. If for some reason the axis order is reversed you can use ‘xy-z’ or ‘xy-z-t’. Note: for 2D+t timelapses where the resolution over x and y are expected to be the same, simply use: ‘z-yx’ (or ‘xy-z’).
- axes: Optional[Tuple[int,…]]
Axes over which to apply low-pass filtering. (advanced)
- other_filters: bool
if True other filters similar to Butterworth are tried such as Type II Chebyshev filter.
- min_padding: int
Minimum amount of padding to be added to avoid edge effects. (advanced)
- max_padding: int
Maximum amount of padding to be added to avoid edge effects. (advanced)
- min_freq: float
Minimum cutoff frequency to use for calibration. Must be within [0,1], typically close to zero. (advanced)
- max_freq: float
Maximum cutoff frequency to use for calibration. Must be within [0,1], typically close to one. (advanced)
- frequency_tolerance: float
Frequency tolerance within [-1,1]. A positive value lets more high-frequencies to go through the low-pass, negative values bring down the cut-off frequencies, zero has no effect. Positive values reduces the effect of denoising but also lead to conservative filtering that avoids removing potentially important information at the boundary (in frequency space) between signal and noise. This can also improve the appearance of the images by avoiding the impression that the images have been ‘over-blurred’. Increase this value by small steps of 0.05 to reduce blurring if the image seems too fuzzy.
- min_order: float
Minimal order for the Butterworth filter to use for calibration. (advanced)
- max_order: float
Maximal order for the Butterworth filter to use for calibration. If min_order==max_order then no search is performed for the filter’s order. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 256000, 320000, 1’000’000, 2’000’000. We do not recommend values higher than 3000000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: Optional[List[Tuple[int]]]
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- multi_core: bool
Use all CPU cores during calibration. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters. (advanced)
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.butterworth.denoise_butterworth(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], axes: Optional[Tuple[int, ...]] = None, filter_type: str = 'butterworth', freq_cutoff: Union[float, Sequence[float]] = 0.5, order: float = 5, min_padding: int = 2, max_padding: int = 32, multi_core: bool = True)[source]
Denoises the given image by applying a configurable <a href=”https://en.wikipedia.org/wiki/Butterworth_filter”>Butterworth lowpass filter</a>. Remarkably good when your signal does not have high-frequencies beyond a certain cutoff frequency. This is probably the first algorithm that should be tried of all currently available in Aydin. It is actually quite impressive how well this performs in practice. If the signal in your images is band-limited as is often the case for microscopy images, this denoiser will work great.
Note: We recommend applying a variance stabilisation transform to improve results for images with non-Gaussian noise.
- Parameters
- image: ArrayLike
Image to be denoised
- axes: Optional[Tuple[int,…]]
Axes over which to apply lowpass filtering.
- filter_type: str
Type of filter. The default is ‘butterworth’ but we have now introduced another filter type: ‘chebyshev2’ which is a Type II Chebyshev filter with a steeper cut-off than Butterworth at the cost of some ripples in the rejected high frequencies. (advanced)
- freq_cutoff: Union[float, Sequence[float]]
Single or sequence cutoff frequency, must be within [0, 1]
- order: float
Filter order, typically an integer above 1.
- min_padding: int
Minimum amount of padding to be added to avoid edge effects.
- max_padding: int
Maximum amount of padding to be added to avoid edge effects.
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery.
- Returns
- Denoised image
Dictionary fixed
- aydin.it.classic_denoisers.dictionary_fixed.calibrate_denoise_dictionary_fixed(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[int] = None, try_omp: bool = True, try_lasso_lars: bool = False, try_lasso_cd: bool = False, try_lars: bool = False, try_threshold: bool = False, num_sparsity_values_to_try: int = 6, dictionaries: str = 'dct', crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 128, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_dictionary: bool = False, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the dictionary-based denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- imageArrayLike
Image to calibrate denoiser for.
- patch_sizeint
Patch size. Common parameter to both ‘learned’, or ‘fixed’ dictionary types. (advanced)
- try_omp: bool
Whether OMP should be tried as a sparse coding algorithm during calibration.
- try_lasso_lars: bool
Whether LASSO-LARS should be tried as a sparse coding algorithm during calibration.
- try_lasso_cd: bool
Whether LASSO-CD should be tried as a sparse coding algorithm during calibration.
- try_lars: bool
Whether LARS should be tried as a sparse coding algorithm during calibration.
- try_threshold: bool
Whether ‘threshold’’ should be tried as a sparse coding algorithm during calibration.
- num_sparsity_values_to_try: int
Maximum number of sparsity values to try during calibration (advanced)
- dictionaries: str
Fixed dictionaries to be included. Can be: ‘dct’, ‘dst’.
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_dictionary: bool
If True displays dictionary with napari – for debug purposes. (advanced) (hidden)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.dictionary_fixed.denoise_dictionary_fixed(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], dictionary=None, coding_mode: str = 'omp', sparsity: int = 1, gamma: float = 0.001, multi_core: bool = True, **kwargs)[source]
Denoises the given image using sparse-coding over a fixed dictionary of nD image patches. The dictionary learning and patch sparse coding uses scikit-learn’s Batch-OMP implementation.
- Parameters
- image: ArrayLike
nD image to be denoised
- dictionary: ArrayLike
Dictionary to use for denosing image via sparse coding. By default (None) a fixed dictionary is used.
- coding_mode: str
Type of sparse coding, can be: ‘lasso_lars’, ‘lasso_cd’, ‘lars’, ‘omp’, or ‘threshold’
- sparsity: int
How many atoms are used to represent each patch after denoising.
- gamma: float
How much the periphery of teh patches contributes to the final denoised image. Larger gamma means that we keep more of the central pixels of the patches, smaller values lead to a more uniform contribution. A value of 1 corresponds to the default blackman window.
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery.
- Returns
- Denoised image
Dictionary learned
- aydin.it.classic_denoisers.dictionary_learned.calibrate_denoise_dictionary_learned(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[int] = None, try_omp: bool = True, try_lasso_lars: bool = False, try_lasso_cd: bool = False, try_lars: bool = False, try_threshold: bool = False, max_patches: Optional[int] = 1000000, dictionary_size: Optional[int] = None, over_completeness: float = 3, max_dictionary_size: int = 256, try_kmeans: bool = True, try_pca: bool = True, try_ica: bool = False, try_sdl: bool = False, num_sparsity_values_to_try: int = 6, optimiser: str = 'fast', num_iterations: int = 1024, batch_size: int = 3, alpha: int = 1, do_cleanup_dictionary: bool = True, do_denoise_dictionary: bool = False, crop_size_in_voxels: Optional[int] = 96000, max_num_evaluations: int = 128, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_dictionary: bool = False, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the dictionary-based denoiser for the given image by finding the best learned dictionary of patches and returns the optimal parameters.
- Parameters
- imageArrayLike
Image to calibrate denoiser for.
- patch_sizeint
Patch size. If None it is automatically adjusted to teh number of dimensions of the image to ensure a reasonable computational effort. (advanced)
- try_omp: bool
Whether OMP should be tried as a sparse coding algorithm during calibration.
- try_lasso_lars: bool
Whether LASSO-LARS should be tried as a sparse coding algorithm during calibration.
- try_lasso_cd: bool
Whether LASSO-CD should be tried as a sparse coding algorithm during calibration.
- try_lars: bool
Whether LARS should be tried as a sparse coding algorithm during calibration.
- try_threshold: bool
Whether ‘threshold’’ should be tried as a sparse coding algorithm during calibration.
- max_patches: Optional[int]
Max number of patches to extract for dictionary learning. If None there is no limit. (advanced)
- dictionary_size: int
Dictionary size in ‘atoms’. If None the dictionary size is inferred from the over_completeness parameter type. (advanced)
- over_completeness: float
Given a certain patch size p and image dimension n, a complete basis has p^n elements, the over completeness factor determines the size of the dictionary relative to that by the formula: ox*p^n. (advanced)
- max_dictionary_size: int
Independently of any other parameter, we limit the size of the dictionary to this provided number. (advanced)
- try_kmeans: bool
Whether to compute a kmeans based dictionary and used it as one of possible dictionaries during calibration.
- try_pca: bool
Whether to compute a PCA based dictionary and used it as one of possible dictionaries during calibration.
- try_ica: bool
Whether to compute an ICA (Independent Component Analysis) based dictionary and used it as one of possible dictionaries during calibration.
- try_sdl: bool
Whether to compute a SDL (Sparse Dictionary Learning) based dictionary and used it as one of possible dictionaries during calibration.
- num_sparsity_values_to_try: int
Maximum number of sparsity values to try during calibration (advanced)
- num_iterations: int
Number of iterations for learning dictionary. (advanced)
- batch_size: int
Size of batches during batched dictionary learning. (advanced)
- alpha: int
Sparsity prior strength. (advanced)
- do_cleanup_dictionary: bool
Removes dictionary entries that are likely pure noise or have impulses or very high-frequencies or checkerboard patterns that are unlikely needed to reconstruct the true signal. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_dictionary: bool
If True displays dictionary with napari – for debug purposes. (advanced) (hidden)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.dictionary_learned.denoise_dictionary_learned(*args, **kwargs)[source]
Denoises the given image using sparse-coding over a fixed dictionary of nD image patches. The dictionary learning and patch sparse coding uses scikit-learn’s Batch-OMP implementation.
- Parameters
- args
- kwargs
- Returns
- denoised image
Gaussian
- aydin.it.classic_denoisers.gaussian.calibrate_denoise_gaussian(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], axes: Optional[Tuple[int, ...]] = None, min_sigma: float = 1e-06, max_sigma: float = 2.0, crop_size_in_voxels: Optional[int] = 128000, optimiser: str = 'fast', max_num_evaluations: int = 512, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'median', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Gaussian denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate denoiser for.
- axes: Optional[Tuple[int,…]]
Axes over which to apply low-pass filtering. (advanced)
- min_sigma: float
Minimum sigma for Gaussian filter. (advanced)
- max_sigma: float
Maximum sigma for Gaussian filter.
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.gaussian.denoise_gaussian(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], axes: Optional[Tuple[int, ...]] = None, sigma: float = 1.0, truncate: float = 4.0, **kwargs)[source]
Denoises the given image using a simple Gaussian filter. Difficult to beat in terms of speed and often provides sufficient although not superb denoising performance. You should always try simple and fast denoisers first, and see if that works for you. If it works and is sufficient for your needs, why go for slower and more complex and slower approach? The only weakness of gaussian filtering is that it affects all frequencies. In contrast, the auto-tuned Butterworth denoiser will not blur within the estimated band-pass of the signal. Thus we recommend you use the Butterworth denoiser instead unless you have a good reason to use this one.
Note: We recommend applying a variance stabilisation transform to improve results for images with non-Gaussian noise.
- Parameters
- image: ArrayLike
nD image to denoise
- axes: Optional[Tuple[int,…]]
Axes over which to apply low-pass filtering. (advanced)
- sigma: float
Standard deviation for Gaussian kernel.
- truncate: float
Truncate the filter at this many standard deviations.
- Returns
- Denoised image
Gaussian-Median
- aydin.it.classic_denoisers.gm.calibrate_denoise_gm(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], max_filter_size: int = 3, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'median', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Gaussian-Median mix denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate denoiser for.
- max_filter_sizeint
Max filter size to use during calibration. Should be a positive odd number such as 3, 5, 7, …
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.gm.denoise_gm(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], sigma: float = 0.5, size: int = 3, factor: float = 2, alpha: float = 0.25, beta: float = 0.3, gamma: float = 0.5, **kwargs)[source]
Denoises the given image with a linear mixing of median filtering and Gaussian filtering. Simple and fast but quite effective for low to moderate noise levels and images with band-limited signal (~ there is a ‘PSF’).
Note: We recommend applying a variance stabilisation transform to improve results for images with non-Gaussian noise.
- Parameters
- image: ArrayLike
Image to be denoised.
- sigma: float
Gaussian blur sigma.
- size: int
Size of the median filter
- factor: float
Ratio between the scales of the two scales
- alpha: float
First mixing coefficient.
- beta: float
First mixing coefficient.
- gamma: float
First mixing coefficient.
- Returns
- Denoised image
Harmonic
- aydin.it.classic_denoisers.harmonic.calibrate_denoise_harmonic(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], rank: bool = False, crop_size_in_voxels: Optional[int] = 256000, optimiser: str = 'fast', max_num_evaluations: int = 16, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Harmonic denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate denoiser for.
- rank: bool
If true, uses a better estimate of min and max filters using a rank filter, may be much slower. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.harmonic.denoise_harmonic(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], filter: str = 'uniform', rank: bool = False, max_iterations: int = 1024, epsilon: float = 1e-08, alpha: float = 0.5, step: float = 0.1, max_gradient: float = 32, **kwargs)[source]
Denoises the given image by applying a non-linear <a href=”https://en.wikipedia.org/wiki/Harmonic_function”>harmonic</a> prior. The gradient of the prior term is a laplace-like operator that is scaled with the range of values around the pixel. One of its specificities is that it is very effective at smoothing uniform regions of an image.
Note: Works well in practice, but a bit slow as currently implemented for large images.
- Parameters
- image: ArrayLike
Image to be denoised
- filter: str
Type of filter used to compute the Laplace-like prior. Can be either ‘uniform’, ‘gaussian’ or ‘median’.
- rank: bool
Uses a more robust estimation of the range.
- max_iterations: int
Max number of iterations.
- epsilon: float
Small value used to determine convergence.
- alpha: float
Balancing between data and prior term. A value of 0 favours the prior entirely, whether a value of 1 favours the data term entirely.
- step: float
Starting step used for gradient descent
- max_gradient: float
Maximum gradient tolerated – usefull to avoid ‘numerical explosions’ ;-)
- Returns
- Denoised image
Lipschitz
- aydin.it.classic_denoisers.lipschitz.calibrate_denoise_lipschitz(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], lipschitz: float = 0.1, percentile: float = 0.001, alpha: float = 0.1, max_num_iterations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, **other_fixed_parameters)[source]
Calibrates the Lipschitz denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate Sobolev denoiser for.
- lipschitzfloat
Increase to tolerate more variation, decrease to be more aggressive in removing salt & pepper noise.
- percentilefloat
Percentile value used to determine the threshold for choosing the worst offending voxels per iteration. (advanced)
- alphafloat
This constant controls the amount of correction per iteration. Should be a number within[0, 1]. (advanced)
- max_num_iterations: int
Maximum number of Lipschitz correction iterations to run. (advanced)
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters. (advanced)
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.lipschitz.denoise_lipschitz(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], lipschitz: float = 0.05, percentile: float = 0.01, alpha: float = 0.1, max_num_iterations: int = 128, multi_core: bool = True)[source]
Denoises the given image by correcting voxel values that violate <a href=”https://en.wikipedia.org/wiki/Lipschitz_continuity”>Lipschitz continuity</a> criterion. These voxels get replaced iteratively replaced by the median. This is repeated for a number of iterations (max_num_iterations), until no more changes to the image occurs, and making sure that the proportion of corrected voxels remains below a given level (max_corrections argument).
- Parameters
- image: ArrayLike
Image to be denoised
- lipschitzfloat
Increase to tolerate more variation, decrease to be more aggressive in removing impulse/salt&pepper noise.
- percentilefloat
Percentile value used to determine the threshold for choosing the worst offending voxels per iteration. (advanced)
- alphafloat
This constant controls the amount of correction per ietartion. Should be a number within[0, 1]. (advanced)
- max_num_iterations: int
Maximum number of Lipschitz correction iterations to run. (advanced)
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery. (advanced)
- Returns
- Denoised image
Non-Local Means(NLM)
- aydin.it.classic_denoisers.nlm.calibrate_denoise_nlm(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: int = 7, patch_distance: int = 11, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Non-Local Means (NLM) denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate denoiser for.
- patch_sizeint, optional
Size of patches used for denoising. (advanced)
- patch_distanceint, optional
Maximal distance in pixels where to search patches used for denoising. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.nlm.denoise_nlm(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: int = 7, patch_distance: int = 11, cutoff_distance: float = 0.1, sigma=0.0)[source]
Denoise given image using either scikit-image implementation of <a href=”https://en.wikipedia.org/wiki/Non-local_means”>Non-Local-Means (NLM)</a>.
- Parameters
- imageArayLike
Image to be denoised
- patch_sizeint, optional
Size of patches used for denoising.
- patch_distanceint, optional
Maximal distance in pixels where to search patches used for denoising.
- cutoff_distancefloat, optional
Cut-off distance (in gray levels). The higher h, the more permissive one is in accepting patches. A higher h results in a smoother image, at the expense of blurring features. For a Gaussian noise of standard deviation sigma, a rule of thumb is to choose the value of h to be sigma of slightly less.
- sigmafloat, optional
The standard deviation of the (Gaussian) noise. If provided, a more robust computation of patch weights is computed that takes the expected noise variance into account (see Notes below).
- Returns
- Denoised image as ndarray.
PCA
- aydin.it.classic_denoisers.pca.calibrate_denoise_pca(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[Union[int, Tuple[int], str]] = None, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 16, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', multi_core: bool = True, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Principal Component Analysis (PCA) denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate spectral denoiser for.
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- multi_core: bool
Use all CPU cores during calibration. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.pca.denoise_pca(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], patch_size: Optional[Union[int, Tuple[int]]] = None, threshold: float = 0.1, reconstruction_gamma: float = 0, multi_core: bool = True)[source]
Denoises the given image by first applying the patch transform, and then doing a PCA projection of these patches along the first components. The cut-off is set by a threshold parameter.
- Parameters
- image: ArrayLike
Image to denoise
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be: ‘full’ for a single patch covering the whole image, ‘half’, ‘quarter’, or an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results.
- threshold: float
Threshold for proportion of components to retain. Between 0 and 1
- reconstruction_gamma: float
Patch reconstruction parameter
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery.
- Returns
- Denoised image
Spectral
- aydin.it.classic_denoisers.spectral.calibrate_denoise_spectral(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], axes: Optional[Tuple[int, ...]] = None, patch_size: Optional[Union[int, Tuple[int], str]] = None, try_dct: bool = True, try_fft: bool = False, try_dst: bool = False, max_order: float = 6.0, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 128, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', multi_core: bool = True, display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Spectral denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
- Parameters
- image: ArrayLike
Image to calibrate spectral denoiser for.
- axes: Optional[Tuple[int,…]]
Axes over which to apply the spectral transform (dct, dst, fft) for denoising each patch.
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be: ‘full’ for a single patch covering the whole image, ‘half’, ‘quarter’, or an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results. (advanced)
- try_dct: bool
Tries DCT transform during optimisation.
- try_fft: bool
Tries FFT transform during optimisation.
- try_dst: bool
Tries DST ransform during optimisation.
- max_order: float
Maximal order for the Butterworth filter. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- multi_core: bool
Use all CPU cores during calibration. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.spectral.denoise_spectral(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], axes: Optional[Tuple[int, ...]] = None, patch_size: Optional[Union[int, Tuple[int], str]] = None, mode: str = 'dct', threshold: float = 0.5, freq_bias_stength: float = 1, freq_cutoff: Union[float, Sequence[float]] = 0.5, order: float = 1, reconstruction_gamma: float = 0, multi_core: bool = True)[source]
Denoises the given image by first applying the patch transform, and then zeroing Fourier/DCT/DST coefficients below a given threshold. In addition, we apply Butterworth filter to suppress frequencies above the band-pass and a configurable frequency bias before applying the thresholding to favour suppressing high versus low frequencies.
Note: This seems like a lot of parameters, but thanks to our auto-tuning approach these parameters are all automatically determined 😊.
- Parameters
- image: ArrayLike
Image to denoise
- axes: Optional[Tuple[int,…]]
Axes over which to apply the spetcral transform (dct, dst, fft) for denoising each patch.
- patch_size: int
Patch size for the ‘image-to-patch’ transform. Can be: ‘full’ for a single patch covering the whole image, ‘half’, ‘quarter’, or an int s that corresponds to isotropic patches of shape: (s,)*image.ndim, or a tuple of ints. By default (None) the patch size is chosen automatically to give the best results.
- mode: str
Possible modes are: ‘dct’(works best!), ‘dst’, and ‘fft’.
- threshold: float
Threshold between 0 and 1
- freq_bias_stength: float
Frequency bias: closer to zero: no bias against high frequencies, closer to one and above: stronger bias towards high-frequencies.
- freq_cutoff: float
Cutoff frequency, must be within [0, 1]. In addition
- order: float
Filter order, typically an integer above 1.
- reconstruction_gamma: float
Patch reconstruction parameter
- multi_core: bool
By default we use as many cores as possible, in some cases, for small (test) images, it might be faster to run on a single core instead of starting the whole parallelization machinery.
- Returns
- Denoised image
Total Variation(TV)
- aydin.it.classic_denoisers.tv.calibrate_denoise_tv(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], enable_mixing: bool = True, crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'fast', max_num_evaluations: int = 512, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates the Total Variation (TV) denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
Note: we use the scikt-image implementation of TV denoising.
- Parameters
- image: ArrayLike
Image to calibrate TV denoiser for.
- enable_mixing: bool
TV denoising tends to return very non-natural looking piece-wise constant images. To mitigate this we give the option to mix a bit of the original image denoised with a Gaussian filter. The sigma for the Gaussian filter is also calibrated. Note: In some cases it might be simply better to not use the TV denoised image and instead just use the Gaussian-filter-denoised image, check the “beta” parameter during optimisation, if that number is very close to 1.0 then you know you should probably use a Butterworth or Gaussian denoiser.
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function, dictionary containing optimal parameters,
- and free memory needed in bytes for computation.
- aydin.it.classic_denoisers.tv.denoise_tv(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], algorithm: str = 'bregman', weight: float = 1, alpha: float = 1.0, beta: float = 0.0, sigma: float = 0.0, **kwargs)[source]
Denoises the given image using either scikit-image implementation of Bregman or Chambolle <a href=”https://en.wikipedia.org/wiki/Total_variation_denoising”>Total Variation (TV) denoising</a>. We attempt to rescale the weight parameter to obtain similar results between Bregman and Chambolle for the same weight.
Note: Because of limitations of the current scikit-image implementation, if an image with more than 2 dimensions is passed, we use the Chambolle implementation as it supports nD images…
- Parameters
- image: ArrayLike
Image to denoise
- algorithm: str
Algorithm to apply: either ‘bregman’ or ‘chambolle’
- weight: float
Weight to balance data term versus prior term. Larger values correspond to a stronger prior during optimisation, and thus more aggressive denoising
- alpha: float
TV denoising tends to return images that are dimmer, we have the option of pushing the brightness here..
- beta: float
TV denoising tends to return very non-natural looking images, here we give the option to ‘mix-in’ back a bit of the original image denoised with a gaussian filter.
- sigma: float
Sigma for gaussian filtered image that is mixed with the TV denoised image.
- kwargs
Any other parameters to be passed to scikit-image implementations
- Returns
- Denoised image
Wavelet
- aydin.it.classic_denoisers.wavelet.calibrate_denoise_wavelet(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], all_wavelets: bool = False, wavelet_name_filter: str = '', crop_size_in_voxels: Optional[int] = 96000, optimiser: str = 'smart', max_num_evaluations: int = 256, blind_spots: Optional[List[Tuple[int]]] = None, jinv_interpolation_mode: str = 'gaussian', display_images: bool = False, display_crop: bool = False, **other_fixed_parameters)[source]
Calibrates a <a href=”https://en.wikipedia.org/wiki/Wavelet_transform “>wavelet</a> denoiser for the given image and returns the optimal parameters obtained using the N2S loss.
Note: we use the scikit-image implementation of wavelet denoising.
- Parameters
- image: ArrayLike
Image to calibrate wavelet denoiser for.
- all_wavelets: bool
If true then all wavelet transforms are tried during calibration, otherwise only a selection that we consider to be the best. Note: trying all transforms can take a long time but might find the magical transform that will make it work for your data. (advanced)
- wavelet_name_filter: str
Comma separated list of wavelet name substrings. We only keep for calibration wavelets which name contains these substrings. Best used when using all transforms as starting list to select a family of wavelets, or to select a specific one by providing its name in full. (advanced)
- crop_size_in_voxels: int or None for default
Number of voxels for crop used to calibrate denoiser. Increase this number by factors of two if denoising quality is unsatisfactory – this can be important for very noisy images. Values to try are: 65000, 128000, 256000, 320000. We do not recommend values higher than 512000.
- optimiser: str
Optimiser to use for finding the best denoising parameters. Can be: ‘smart’ (default), or ‘fast’ for a mix of SHGO followed by L-BFGS-B. (advanced)
- max_num_evaluations: int
Maximum number of evaluations for finding the optimal parameters. Increase this number by factors of two if denoising quality is unsatisfactory.
- blind_spots: bool
List of voxel coordinates (relative to receptive field center) to be included in the blind-spot. For example, you can give a list of 3 tuples: [(0,0,0), (0,1,0), (0,-1,0)] to extend the blind spot to cover voxels of relative coordinates: (0,0,0),(0,1,0), and (0,-1,0) (advanced) (hidden)
- jinv_interpolation_mode: str
J-invariance interpolation mode for masking. Can be: ‘median’ or ‘gaussian’. (advanced)
- display_images: bool
When True the denoised images encountered during optimisation are shown. (advanced) (hidden)
- display_crop: bool
Displays crop, for debugging purposes… (advanced) (hidden)
- other_fixed_parameters: dict
Any other fixed parameters
- Returns
- Denoising function and dictionary containing optimal parameters.
- aydin.it.classic_denoisers.wavelet.denoise_wavelet(image: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], wavelet: str = 'db1', sigma: Optional[float] = None, mode: str = 'soft', method: str = 'BayesShrink', **kwargs)[source]
Denoises the given image using the scikit-image implementation of <a href=”https://en.wikipedia.org/wiki/Wavelet_transform “> wavelet</a> denoising.
Note: we use the scikt-image implementation of wavelet denoising.
- Parameters
- image: ArrayLike
Image to denoise
- waveletstring, optional
The type of wavelet to perform and can be any of the options
pywt.wavelist
outputs. The default is ‘db1’. For example,wavelet
can be any of{'db2', 'haar', 'sym9'}
and many more (see PyWavelets documentation).- sigmafloat or list, optional
The noise standard deviation used when computing the wavelet detail coefficient threshold(s). When None (default), the noise standard deviation is estimated via the method in (2)_.
- mode{‘soft’, ‘hard’}, optional
An optional argument to choose the type of denoising performed. It noted that choosing soft thresholding given additive noise finds the best approximation of the original image.
- method{‘BayesShrink’, ‘VisuShrink’}, optional
Thresholding method to be used. The currently supported methods are “BayesShrink” (1)_ and “VisuShrink” (2)_. Defaults to “BayesShrink”.
- kwargsdict
Any other parameters to be passed to scikit-image implementations
- Returns
- Denoised image as ndarray