deinterlacing package

Submodules

Module contents

class deinterlacing.DeinterlaceParameters(*args, **kwargs)[source]

Bases: object

DeinterlaceParameters encapsulates the parameters utilized in deinterlacing to control the deinterlacing process. The structure also contains validation logic to ensure that the parameters are appropriate for the provided images.

Variables:
  • block_size – f

  • pool – f

  • unstable – f

  • subsearch – f

  • align – f

  • has_turnaround – f

  • null_edges – f

  • use_gpu – f

  • images – f

Parameters:
  • __dataclass_self__ (PydanticDataclass)

  • args (Any)

  • kwargs (Any)

align: Literal['pixel', 'subpixel', 'variable']
block_size: int | None
images: InitVar = None
pool: Literal['mean', 'median', 'std', 'sum', None]
subsearch: int | None
unstable: int | None
use_gpu: bool
validate_with_images(images)[source]

Validate the parameters against the provided images..

Parameters:

images (ndarray) – The images to validate against.

Return type:

None

Returns:

None

deinterlacing.deinterlace(images, parameters=None)[source]

Deinterlace images collected using resonance-scanning microscopes such that the forward and backward-scanned lines are properly aligned. A fourier-approach is utilized: the fourier transform of the two sets of lines is computed to calculate the cross-power spectral density. Taking the inverse fourier transform of the cross-power spectral density yields a matrix whose peak corresponds to the sub-pixel offset between the two sets of lines. This translative offset was then discretized and used to shift the backward-scanned lines.

Unfortunately, the fast-fourier transform methods that underlie the implementation of the deinterlacing algorithm have poor spatial complexity (i.e., large memory constraints). This weakness is particularly problematic when using GPU-parallelization. To mitigate these issues, deinterlacing can be performed batch-wise while maintaining numerically identical results (see block_size).

To improve performance, the deinterlacing algorithm can be applied to a pool of the images while maintaining efficacy. Specifically, setting the pool parameter will apply the deinterlacing algorithm to the the standard deviation of each pixel across a block of images. This approach is better suited to images with limited signal-to-noise or sparse activity than simply operating on every n-th frame.

Finally, it is often the case that the auto-alignment algorithms used in microscopy software are unstable until a sufficient number of frames have been collected. Therefore, the unstable parameter can be used to specify the number of frames that should be deinterlaced individually before switching to batch-wise processing.

Note

This function operates in-place.

Warning

The number of frames included in each fourier transform must be several times smaller than the maximum number of frames that fit within your GPU’s VRAM (CuPy) or RAM (NumPy). This function will not automatically revert to the NumPy implementation if there is not sufficient VRAM. Instead, an out of memory error will be raised.

Parameters:
Return type:

None