aspire.denoising package

Submodules

aspire.denoising.adaptive_support module

aspire.denoising.adaptive_support.adaptive_support(img_src, energy_threshold=0.99)

Determine size of the compact support in both real and Fourier Space.

Returns c_limit (support radius in Fourier space), and R_limit (support radius in real space).

Fourier c_limit is scaled in range [0, 0.5]. R_limit is in pixels [0, Image.resolution/2].

Parameters:
  • img_src – Input Source of images.

  • energy_threshold – [0, 1] threshold limit

Returns:

(c_limit, R_limit)

aspire.denoising.class_avg module

class aspire.denoising.class_avg.ClassAvgSource(src, classifier, class_selector, averager, batch_size=512)

Bases: ImageSource

Source for denoised 2D images using class average methods.

Constructor of an object for denoising 2D images using class averaging methods.

Parameters:
  • src – Source used for image classification.

  • classifier – Class2D subclass used for image classification. Example, RIRClass2D.

  • class_selector – A ClassSelector subclass.

  • averager – An Averager2D subclass.

  • batch_size – Integer size for batched operations.

property class_distances

Returns table of class image distances as (src.n, n_nbors) Numpy array.

Follows same layout as class_indices but holds floats representing the distance (returned by classifier) to the zeroth image in each class.

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, self.dtype.

property class_indices

Returns table of class image indices as (src.n, n_nbors) Numpy array.

Each row reprsents a class, with the columns ordered by smallest class_distances from the reference image (zeroth columm).

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, integers.

property class_refl

Returns table of class image reflections as (src.n, n_nbors) Numpy array.

Follows same layout as class_indices but holds booleans that are True when the image should be reflected before averaging.

Note n_nbors is managed by self.classifier and used here for documentation.

Returns:

Numpy array, boolean.

property n
save(*args, **kwargs)

Save metadata to STAR file.

See ImageSource.save for documentation.

property selection_indices
class aspire.denoising.class_avg.ClassAvgSourcev132(src, n_nbor=50, classifier=None, class_selector=None, averager=None, averager_src=None, batch_size=512)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

Defaults to using SNR based class selection, avoiding neighbors of previous classes, and a brute force image alignment (rotational only).

Instantiates ClassAvgSourcev132 with the following parameters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates GlobalWithRepulsionClassSelector with BandedSNRImageQualityFunction. This will select the images with the highest banded SNR.

  • averagerAverager2D instance. Default None creates BFRAverager2D instance. See code for parameter details.

  • averager_src

    Optionally explicitly assign source to averager during initialization. Allows users to

    provide distinct sources for classification and averaging. Raises error when combined with an explicit averager argument.

  • batch_size – Integer size for batched operations.

Returns:

ClassAvgSource instance.

class aspire.denoising.class_avg.ClassAvgSourcev140(src, n_nbor=50, classifier=None, class_selector=None, averager=None, averager_src=None, batch_size=512)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

Defaults to using global variance based class selection, and a brute force image alignment (rotational only).

This is most similar to what was reported for papers using the MATLAB code, but takes significant time to compute.

Instantiates ClassAvgSourcev140 with the following parameters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates GlobalVarianceClassSelector.

  • averagerAverager2D instance. Default None creates BFTAverager2D instance. See code for parameter details.

  • averager_src

    Optionally explicitly assign source to averager during initialization. Allows users to

    provide distinct sources for classification and averaging. Raises error when combined with an explicit averager argument.

  • batch_size – Integer size for batched operations.

Returns:

ClassAvgSource instance.

class aspire.denoising.class_avg.DebugClassAvgSource(src, n_nbor=10, classifier=None, class_selector=None, averager=None, batch_size=512)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

In this context Debug means defaulting to:
  • Using the defaults for RIRClass2D.

  • Using TopClassSelector to select all classes maintaining the same order as the input source.

  • Using BFRAverager2D with defaults on a single core.

Instantiates with default debug paramaters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 10.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates TopClassSelector.

  • averagerAverager2D instance. Default None creates BFRAverager2D instance. See code for parameter details.

  • batch_size – Integer size for batched operations.

Returns:

ClassAvgSource instance.

aspire.denoising.class_avg.DefaultClassAvgSource(src, n_nbor=50, classifier=None, class_selector=None, averager=None, averager_src=None, batch_size=512, version=None)

Source for denoised 2D images using class average methods.

Accepts version, to dispatch ClassAvgSource with parameters below. Default version is latest available. Different versions may have different defaults.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance.

  • averagerAverager2D instance.

  • averager_src

    Optionally explicitly assign source to averager during initialization. Allows users to

    provide distinct sources for classification and averaging. Raises error when combined with an explicit averager argument.

  • batch_size – Integer size for batched operations.

  • version – Optionally selects a versioned DefaultClassAvgSource. Defaults to latest available.

Returns:

ClassAvgSource instance.

class aspire.denoising.class_avg.LegacyClassAvgSource(src, n_nbor=50, classifier=None, class_selector=None, averager=None, averager_src=None, batch_size=512)

Bases: ClassAvgSource

Source for denoised 2D images using class average methods.

Defaults to using global variance based class selection, and a rotational image alignment. Translational alignment is skipped by default (images are assumed reasonably centered), but can be configured by supplying a custom averager=BFTAverager2D(…) argument.

This is similar to what was reported for papers using the MATLAB code.

Instantiates ClassAvgSource with the following parameters.

Parameters:
  • src – Source used for image classification.

  • n_nbor – Number of nearest neighbors. Default 50.

  • classifierClass2D classifier instance. Default None creates RIRClass2D. See code for parameter details.

  • class_selectorClassSelector instance. Default None creates GlobalVarianceClassSelector.

  • averagerAverager2D instance. Default None creates BFTAverager2D instance. See code for parameter details.

  • averager_src

    Optionally explicitly assign source to averager during initialization. Allows users to

    provide distinct sources for classification and averaging. Raises error when combined with an explicit averager argument.

  • batch_size – Integer size for batched operations.

Returns:

ClassAvgSource instance.

aspire.denoising.denoised_src module

class aspire.denoising.denoised_src.DenoisedSource(src, denoiser)

Bases: ImageSource

ImageSource class serving denoised 2D images.

Initialize a denoised ImageSource object from an ImageSource.

Parameters:
  • src – Original ImageSource object storing noisy images

  • denoiser – A Denoiser object for specifying a method for denoising

aspire.denoising.denoiser module

class aspire.denoising.denoiser.Denoiser(src)

Bases: ABC

Base class for 2D image denoisers.

Initialize an object for denoising 2D images from src.

Parameters:

srcImageSource providing noisy images.

property denoise

Subscriptable property returning 2D images after denoising.

See _ImageAccessor.

aspire.denoising.denoiser_cov2d module

class aspire.denoising.denoiser_cov2d.DenoiserCov2D(src, basis=None, var_noise=None, batch_size=512, covar_opt=None)

Bases: Denoiser

Define a derived class for denoising 2D images using Cov2D method

Initialize an object for denoising 2D images using Cov2D method

Parameters:
  • src – The source object of 2D images with metadata

  • basis – The basis method to expand 2D images

  • var_noise – The estimated variance of noise

  • batch_size – Integer batch size for processing images. Defaults to 512.

  • covar_opt – Optional dictionary of option overides for Cov2D. Provided options will supersede defaults in DenoiserCov2D.default_opt.

build_denoiser()

Build estimated mean and covariance matrix of 2D images.

This method should be computed once, on first images access.

default_opt = {'iter_callback': [], 'max_iter': 250, 'rel_tolerance': 1e-12, 'shrinker': 'frobenius_norm', 'store_iterates': False, 'verbose': 0}
aspire.denoising.denoiser_cov2d.src_wiener_coords(sim, mean_vol, eig_vols, lambdas=None, noise_var=0, batch_size=512)

Calculate coordinates using Wiener filter

Parameters:
  • sim – A simulation object containing the images whose coordinates we want.

  • mean_vol – The mean volume of the source as Volume instance.

  • eig_vols – The eigenvolumes of the source as Volume instance.

  • lambdas – The eigenvalues in a K-by-K diagonal matrix (default eye(K)).

  • noise_var – The variance of the noise in the images (default 0).

  • batch_size – The size of the batches in which to compute the coordinates (default 512).

Returns:

A K-by-src.n array of coordinates corresponding to the Wiener filter coordinates of each image in sim.

The coordinates are obtained by the formula

alpha_s = eig_vols^T H_s ( y_s - P_s mean_vol ) ,

where P_s is the forward image mapping and y_s is the sth image,

H_s = Sigma * P_s^T ( P_s Sigma P_s^T + noise_var I )^(-1) ,

and Sigma is the covariance matrix eig_vols * lambdas * eig_vols^T. Note that when noise_var is zero, this reduces to the projecting y_s onto the span of P_s eig_vols.

# TODO: Find a better place for this functionality other than in utils

Module contents