Skip to content

Noise Models

Source

GaussianMixtureNoiseModel

Bases: Module

Define a noise model parameterized as a mixture of gaussians.

If config.path is not provided a new object is initialized from scratch. Otherwise, a model is loaded from config.path.

Parameters:

Attributes:

  • min_signal (float) –

    Minimum signal intensity expected in the image.

  • max_signal (float) –

    Maximum signal intensity expected in the image.

  • path (Union[str, Path]) –

    Path to the directory where the trained noise model (*.npz) is saved in the train method.

  • weight (Parameter) –

    A [3*n_gaussian, n_coeff] sized array containing the values of the weights describing the GMM noise model, with each row corresponding to one parameter of each gaussian, namely [mean, standard deviation and weight]. Specifically, rows are organized as follows: - first n_gaussian rows correspond to the means - next n_gaussian rows correspond to the weights - last n_gaussian rows correspond to the standard deviations If weight=None, the weight array is initialized using the min_signal and max_signal parameters.

  • n_gaussian (int) –

    Number of gaussians in the mixture.

  • n_coeff (int) –

    Number of coefficients to describe the functional relationship between gaussian parameters and the signal. 2 implies a linear relationship, 3 implies a quadratic relationship and so on.

  • device (device) –

    GPU device.

  • min_sigma (float) –

    All values of standard deviation below this are clamped to this value.

fit(signal, observation, learning_rate=0.1, batch_size=250000, n_epochs=2000, lower_clip=0.0, upper_clip=100.0)

Training to learn the noise model from signal - observation pairs.

Parameters:

  • signal (NDArray) –

    Clean Signal Data

  • observation (NDArray) –

    Noisy Observation Data

  • learning_rate (float, default: 0.1 ) –

    Learning rate. Default = 1e-1.

  • batch_size (int, default: 250000 ) –

    Nini-batch size. Default = 250000.

  • n_epochs (int, default: 2000 ) –

    Number of epochs. Default = 2000.

  • lower_clip (int, default: 0.0 ) –

    Lower percentile for clipping. Default is 0.

  • upper_clip (int, default: 100.0 ) –

    Upper percentile for clipping. Default is 100.

get_gaussian_parameters(signals)

Returns the noise model for given signals

Parameters:

  • signals (Tensor) –

    Underlying signals

Returns:

  • noise_model ( list of Tensor ) –

    Contains a list of mu, sigma and alpha for the signals

get_signal_observation_pairs(signal, observation, lower_clip, upper_clip)

Returns the Signal-Observation pixel intensities as a two-column array

Parameters:

  • signal (numpy array) –

    Clean Signal Data

  • observation (NDArray) –

    Noisy observation Data

  • lower_clip (float) –

    Lower percentile bound for clipping.

  • upper_clip (float) –

    Upper percentile bound for clipping.

Returns:

  • noise_model ( list of torch floats ) –

    Contains a list of mu, sigma and alpha for the signals

likelihood(observations, signals)

Evaluates the likelihood of observations given the signals and the corresponding gaussian parameters.

Parameters:

  • observations (Tensor) –

    Noisy observations. Shape is (batch, 1, dim1, dim2).

  • signals (Tensor) –

    Underlying signals. Shape is (batch, 1, dim1, dim2).

Returns:

  • value ( torch.Tensor: ) –

    Likelihood of observations given the signals and the GMM noise model

normal_density(x, mean, std)

Evaluates the normal probability density at x given the mean mean and standard deviation std.

Parameters:

  • x (Tensor) –

    The ground-truth tensor. Shape is (batch, 1, dim1, dim2).

  • mean (Tensor) –

    The inferred mean of distribution. Shape is (batch, 1, dim1, dim2).

  • std (Tensor) –

    The inferred standard deviation of distribution. Shape is (batch, 1, dim1, dim2).

Returns:

  • tmp ( Tensor ) –

    Normal probability density of x given mean and std

polynomial_regressor(weight_params, signals)

Combines weight_params and signal signals to regress for the gaussian parameter values.

Parameters:

  • weight_params (Tensor) –

    Corresponds to specific rows of the self.weight

  • signals (Tensor) –

    Signals

Returns:

  • value ( Tensor ) –

    Corresponds to either of mean, standard deviation or weight, evaluated at signals

sample_observation_from_signal(signal)

Sample an instance of observation based on an input signal using a learned Gaussian Mixture Model. For each pixel in the input signal, samples a corresponding noisy pixel.

Parameters:

  • signal (NDArray) –

    Clean 2D signal data.

Returns:

  • observation ( numpy array ) –

    An instance of noisy observation data based on the input signal.

save(path, name)

Save the trained parameters on the noise model.

Parameters:

  • path (str) –

    Path to save the trained parameters.

  • name (str) –

    File name to save the trained parameters.

MultiChannelNoiseModel

Bases: Module

__init__(nmodels)

Constructor.

To handle noise models and the relative likelihood computation for multiple output channels (e.g., muSplit, denoiseSplit).

This class: - receives as input a variable number of noise models, one for each channel. - computes the likelihood of observations given signals for each channel. - returns the concatenation of these likelihoods.

Parameters:

likelihood(obs, signal)

Compute the likelihood of observations given signals for each channel.

Parameters:

  • obs (Tensor) –

    Noisy observations, i.e., the target(s). Specifically, the input noisy image for HDN, or the noisy unmixed images used for supervision for denoiSplit. Shape: (B, C, [Z], Y, X), where C is the number of unmixed channels.

  • signal (Tensor) –

    Underlying signals, i.e., the (clean) output of the model. Specifically, the denoised image for HDN, or the unmixed images for denoiSplit. Shape: (B, C, [Z], Y, X), where C is the number of unmixed channels.

create_histogram(bins, min_val, max_val, observation, signal)

Creates a 2D histogram from 'observation' and 'signal'.

Parameters:

  • bins (int) –

    Number of bins in x and y.

  • min_val (float) –

    Lower bound of the lowest bin in x and y.

  • max_val (float) –

    Upper bound of the highest bin in x and y.

  • observation (ndarray) –

    3D numpy array (stack of 2D images). Observation.shape[0] must be divisible by signal.shape[0]. Assumes that n subsequent images in observation belong to one image in 'signal'.

  • signal (ndarray) –

    3D numpy array (stack of 2D images).

Returns:

  • histogram ( ndarray ) –

    A 3D array: - histogram[0]: Normalized 2D counts. - histogram[1]: Lower boundaries of bins along y. - histogram[2]: Upper boundaries of bins along y.

  • The values for x can be obtained by transposing 'histogram[1]' and 'histogram[2]'.

multichannel_noise_model_factory(model_config)

Multi-channel noise model factory.

Parameters:

  • model_config (Optional[MultiChannelNMConfig]) –

    Noise model configuration, a MultiChannelNMConfig config that defines noise models for the different output channels.

Returns:

Raises:

  • NotImplementedError

    If the chosen noise model model_type is not implemented. Currently only GaussianMixtureNoiseModel is implemented.

noise_model_factory(model_config)

Noise model factory for single-channel noise models.

Parameters:

Returns:

Raises:

  • NotImplementedError

    If the chosen noise model model_type is not implemented. Currently only GaussianMixtureNoiseModel is implemented.

train_gm_noise_model(model_config, signal, observation)

Train a Gaussian mixture noise model.

Parameters:

Returns:

  • _description_