Preprocess Module
This module contains functions for image preprocessing before the main analysis. These functions include gaussian smoothing, histogram equalization, and background elimination.
The scout preprocess command can be used to apply these functions as well as convert to a Zarr array.
histogram : estimate image histogram
rescale : remove background below a threshold
denoise : remove noise using wavelet filtering
contrast : apply adaptive histrogram equalization (optional)
convert : convert image(s) to Zarr
- scout.preprocess.clahe(image, kernel_size, clip_limit=0.01, nbins=256, nb_workers=None)
Apply CLAHE to each z-slice in image
- Parameters
image (ndarray) – input image
kernel_size (int or list-like) – shape of the contextual regions
clip_limit (float, optional) – limit for number of clipping pixels
nbins (int, optional) – number of gray bins for histograms
nb_workers (int, optional) – number of workers to use. Default, cpu_count
- Returns
equalized – output image
- Return type
ndarray
- scout.preprocess.denoise(image, sigma, wavelet='db1', nb_workers=None)
Denoise input image slice-by-slice with wavelet filtering
- Parameters
image (ndarray) – Input 3D image
sigma (float) – Noise standard deviation
wavelet (str) – Wavelet to use in DWT. Default, ‘db1’.
nb_workers (int) – Number of parallel processes to use. Default, cpu_count()
- Returns
output – Denoised 3D image
- Return type
ndarray
- scout.preprocess.denoise2d(image, sigma, wavelet='db1')
Denoise input image using wavelet filtering filtering
- Parameters
image (ndarray) – Input 2D image
sigma (float) – Noise standard deviation
wavelet (str) – Wavelet to use in DWT. Default, ‘db1’.
- Returns
output – Denoised 2D image
- Return type
ndarray
- scout.preprocess.gaussian_blur(image, sigma)
Smooth input image by gaussian blurring with sigma kernel.
This function does not normalize the image before applying the gaussian blurring.
- Parameters
image (ndarray) – Input image
sigma (int, tuple) – Blurring amount for each axis
- Returns
blurred – Smoothed image
- Return type
ndarray
- scout.preprocess.gaussian_blur_parallel(arr, sigma, output, chunks, overlap, nb_workers=None)
Smooths a chunked Zarr array with parallel processing.
- Parameters
arr (Zarr Array) –
sigma (int, tuple) –
output (Zarr Array) –
chunks (tuple) –
overlap (int) –
nb_workers (int) –
- scout.preprocess.remove_background(image, threshold, offset=None)
Threshold an image and use as a mask to remove the background. May improve compression
- Parameters
image (ndarray) – input image
threshold (float) – intensity to threshold the input image
offset (float) – intensity to substract from the result
- Returns
output – output image with background set to 0
- Return type
ndarray