Preprocessing
Numpy-based API for preprocessing
The functions in this module focus on “imagestacks,” i.e.,
in the context of this package, arrays of the form N x M0 x M1 x M2.
They are designed to give relatively simple interfaces to
the functionality needed for preprocessing such imagestacks.
Functions:
|
Perform a dead-basic background subtraction (subtracts a blurred version of the imagestack, and clips to stay positive). |
|
Generates a plot which may help determine if there is colorbleed between two frames. |
|
Performs a simple per-frame normalization on the imagestack (subtract min, then divide by mean). |
- bardensr.preprocessing.background_subtraction(imagestack, sigmas)
Perform a dead-basic background subtraction (subtracts a blurred version of the imagestack, and clips to stay positive).
Input:
imagestack, N x M0 x M1 x M2
sigmas, 3 float-ish numbers indicating how much to blur along last 3 axes of the imagestack
- bardensr.preprocessing.colorbleed_plot(framea, frameb)
Generates a plot which may help determine if there is colorbleed between two frames.
Input:
framea (M0 x M1 x M2)
frameb (M0 x M1 x M2)
- bardensr.preprocessing.minmax(imagestack)
Performs a simple per-frame normalization on the imagestack (subtract min, then divide by mean).
Input should be an imagestack of shape N x M0 x M1 x M2
Lower-level tensorflow-based API for preprocessing
The functions in this module accept general tensorflow tensors as arguments and return them as outputs. This has some advantages…
Using these can save time, because tensorflow tensors can live on the GPU, which means you don’t have to copy them back and forth to the CPU.
These functions can also be included inside of tf.function blocks and thus compiled for more speed and memory efficiency.
You can differentiate through them with tensorflow.
Functions:
|
Gaussian filter along a single axis of a tensor |
|
Subtract minimum and divide by maximum along axes. |
- bardensr.preprocessing.preprocessing_tf.gaussian_filter_1d(X, sigma, axis)
Gaussian filter along a single axis of a tensor
Input:
X (a tensor with a float-ish dtype)
sigma (will be cast to float64)
axis (integer)
Output: tensor with the same shape and dtype as “X”, blurred along “axis” with a gaussian filter with “sigma” pixels of standard deviation.
- bardensr.preprocessing.preprocessing_tf.minmax(X, axes)
Subtract minimum and divide by maximum along axes.
Input:
X (M0 x M1 x M2 x M3 … x M(n-1))
axes (integers in the set {0,1,…{n-1})
Output: tensor with the same shape and dtype as X, except normalized along axes. In brief:
X=X-tf.reduce_min(X,axis=axes,keepdims=True) X=X/tf.reduce_max(X,axis=axes,keepdims=True) return X