fluidimage.works.preproc.toolbox#

Preprocess toolbox#

A toolbox of filters which operate on a single image (numpy array). cf. http://www.scipy-lectures.org/advanced/image_processing/

Provides:

class fluidimage.works.preproc.toolbox.PreprocToolsBase(params)[source]#

Bases: object

Base class for wrapping preprocessing functions into a class.

classmethod create_default_params(params)[source]#

Create default parameters from the function argument list.

apply(img)[source]#

Apply all preprocessing tools for which enable is True. Return the preprocessed image (numpy array).

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

class fluidimage.works.preproc.toolbox.PreprocToolsPy(params)[source]#

Bases: PreprocToolsBase

Wrapper class for functions in _toolbox_py module.

adaptive_threshold(window_size=5, offset=0)#

Adaptive threshold transforms a grayscale image to a binary image. Useful in identifying particles.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

window_sizescalar

Sets the size of the pixel neighbourhood to calculate threshold.

offsetscalar

Constant to be subtracted from the mean.

equalize_hist_adapt(window_shape=(10, 10), nbins=256)#

Contrast Limited Adaptive Histogram Equalization (CLAHE). Increases local contrast.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

window_shapetuple of integers

Specifies the shape of the window as follows (dx, dy)

nbinsinteger

Number of bins to calculate histogram

References

equalize_hist_global(nbins=256)#

Increases global contrast of the image. Equalized image would have a roughly linear cumulative distribution function for each pixel neighborhood. It works well when pixel intensities are nearly uniform [1,2].

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

nbinsinteger

Number of bins to calculate histogram

References

equalize_hist_local(radius=10)#

Adaptive histogram equalization (AHE) emphasizes every local graylevel variations [1]. Caution: It has a tendency to overamplify noise in homogenous regions [2].

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

radiusinteger

Radius of the disk shaped window.

References

gamma_correction(gamma=1.0, gain=1.0)#

Gamma correction or power law transform. It can be expressed as:

\[I_{out} = gain \times {I_{in}} ^ {\gamma}\]

Adjusts contrast without changing the shape of the histogram. For the values .. \(\gamma > 1\) : Histogram shifts towards left (darker) .. \(\gamma < 1\) : Histogram shifts towards right (lighter)

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

gammafloat

Non-negative real number

gainfloat

Multiplying factor

References

global_threshold(minima=0.0, maxima=65535.0)#

Trims pixel intensities which are outside the interval (minima, maxima).

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

minima, maximafloat

Sets the threshold

rescale_intensity(minima=0.0, maxima=4096)#

Rescale image intensities, between the specified minima and maxima, by using a multiplicative factor.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

minima, maximafloat

Sets the range to which current intensities have to be rescaled.

rescale_intensity_tanh(threshold=None)#

Rescale image intensities, using a tanh fit. The maximum intensity of the output is set by the threshold parameter.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

threshold:

Value of intensity with which img is normalized img_out = max(img) * tanh( img / threshold) If threshold is None: threshold = 2 * np.sqrt(np.mean(img**2))

sharpen(sigma1=3.0, sigma2=1.0, alpha=30.0)#

Sharpen image edges.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

sigma1, sigma2float

Std deviation for two passes gaussian filters. sigma1 > sigma2

alphafloat

Factor by which the image will be sharpened

sliding_median(weight=1.0, window_size=30, boundary_condition='reflect')#

Subtracts the median calculated within a sliding window from the centre of the window.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

weightscalar

Fraction of median to be subtracted from each pixel. Value of weight should be in the interval (0.0, 1.0).

window_sizescalar or tuple

Sets the size of the sliding window. Specifying window_size=3 is equivalent to window_size=(3,3).

boundary_condition{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}

Mode of handling array borders.

sliding_minima(weight=1.0, window_size=30, boundary_condition='reflect')#

Subtracts the minimum calculated within a sliding window from the centre of the window.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

weightscalar

Fraction of minima to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_sizescalar or tuple

Sets the size of the sliding window. Specifying window_size=3 is equivalent to window_size=(3,3).

boundary_condition{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}

Mode of handling array borders.

sliding_percentile(percentile=10.0, weight=1.0, window_size=30, boundary_condition='reflect')#

Flexible version of median filter. Low percentile values work well for dense images.

Parameters:
imgarray_like

Series of images as a 3D numpy array, or a list or a set

percentilescalar

Percentile to filter. Setting percentile = 50 is equivalent to a sliding_median filter.

weightscalar

Fraction of median to be subtracted from each pixel. Value of weight should be in the interval (0.0, 1.0).

window_shapetuple of integers

Specifies the shape of the window as follows (dt, dy, dx)

boundary_condition{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}

Mode of handling array borders.

temporal_median(weight=1.0, window_shape=None)#

Subtracts the median calculated in time and space, for each pixel. Median filter works well for sparse images.

Parameters:
imgarray_like

Series of images as a 3D numpy array, or a list or a set

weightscalar

Fraction of median to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_shapetuple of integers

Specifies the shape of the window as follows (nt, ny, nx) or (ny, nx).

temporal_minima(weight=1.0, window_shape=None)#

Subtracts the minima calculated in time and space, for each pixel.

Parameters:
imgsarray_like

Series of images as a 3D numpy array, or a list or a set

weightscalar

Fraction of minima to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_shapetuple of integers

Specifies the shape of the window as follows (nt, ny, nx) or (ny, nx).

temporal_percentile(percentile=10.0, weight=1.0, window_shape=None)#

Flexible version of median filter. Low percentile values work well for dense images.

Parameters:
imgarray_like

Series of images as a 3D numpy array, or a list or a set

percentilescalar

Percentile to filter. Setting percentile = 50 is equivalent to a temporal_median filter.

weightscalar

Fraction of median to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_shapetuple of integers

Specifies the shape of the window as follows (nt, ny, nx) or (ny, nx).

class fluidimage.works.preproc.toolbox.PreprocToolsCV(params)[source]#

Bases: PreprocToolsBase

Wrapper class for functions in _toolbox_cv module.

adaptive_threshold(window_size=5, offset=0)#

Adaptive threshold transforms a grayscale image to a binary image. Useful in identifying particles.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

window_sizescalar

Sets the size of the pixel neighbourhood to calculate threshold.

offsetscalar

Constant to be subtracted from the mean.

global_threshold(minima=0.0, maxima=65535.0)#

Trims pixel intensities which are outside the interval (minima, maxima).

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

minima, maximafloat

Sets the threshold

sliding_median(weight=1.0, window_size=3)#

Subtracts the median calculated within a sliding window from the centre of the window.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

weightscalar

Fraction of median to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_sizeint

Sets the size of the sliding window.

sliding_minima(weight=1.0, window_size=3, boundary_condition='reflect')#

Subtracts the minimum calculated within a sliding window from the centre of the window.

Parameters:
imgarray_like

Single image as numpy array or multiple images as array-like object

weightscalar

Fraction of minima to be subtracted from each pixel. Value of weight should be in the interval (0.0,1.0).

window_sizescalar

Sets the size of the sliding window.

boundary_condition{‘reflect’, ‘default’, ‘constant’, ‘wrap’,

‘transparent’, ‘replicate’}

Mode of handling array borders.

Classes

PreprocToolsBase(params)

Base class for wrapping preprocessing functions into a class.

PreprocToolsCV(params)

Wrapper class for functions in _toolbox_cv module.

PreprocToolsPy(params)

Wrapper class for functions in _toolbox_py module.