iss_preprocess.image package

Submodules

iss_preprocess.image.correction module

iss_preprocess.image.correction.apply_illumination_correction(data_path, stack, prefix, projection=None, dtype=<class 'float'>)

Apply illumination correction

Use precomputed normalised and filtered averages to correct for inhomogeneous illumination

Parameters:
  • data_path (str) – Relative path to the data to read ops and find averages

  • stack (np.array) – A 3 or 4D array with X x Y x Nchannels as first 3 dimensions

  • prefix (str) – Prefix name of the average, e.g. “barcode_round” for grand average or “barcode_round_1” for single round average.

  • projection (str, optional) – Name of the projection to use. If None, will try to get it from ops. Defaults to None.

  • dtype (str or type, optional) – data type of the output. Division is always performed as float

Returns:

Normalised stack. Same shape as input.

Return type:

stack (np.array)

iss_preprocess.image.correction.calculate_unmixing_coefficient(signal_image, background_image, background_coef, threshold_background=None, threshold_signal=None, fit_intercept=True)

Unmixes two images: one with only background autofluorescence and another with both background and useful signal. Uses Linear regression for the unmixing process.

Parameters:
  • background_image – numpy array of the background image.

  • signal_image – numpy array of the image with both signal and background.

  • background_coef – Coefficient to multiply the background image by before subtraction.

  • threshold_background (optional) – Minimum value for a pixel to be considered background. If None will use the median. Default None.

  • threshold_signal (optional) – Minimum value on signal channel for a pixel to be considered background. If None will use the median. Default None.

  • fit_intercept (optional) – Whether to fit an intercept in the linear model. Default True.

Returns:

The isolated signal image after background subtraction. model_coef: Coefficient used to multiply the background image for unmixing. intercept: Intercept of the linear model used for unmixing. valid_pixel: Boolean array of pixels that passed the thresholding.

Return type:

pure_signal_image

iss_preprocess.image.correction.compute_distribution(stack, max_value=4097)

Compute simple tile statistics for one multichannel image

Parameters:
  • stack (np.array) – An X x Y x Nch stack

  • max_value (int) – Maximum value to compute histogram, must be >= stack.max()

Returns:

Distribution of pixel values by channel. Shape (max_value + 1 , Nch)

Return type:

np.array

iss_preprocess.image.correction.filter_stack(stack, r1=2, r2=4, dtype=<class 'float'>)

Filter stack with hanning window

Convolve each image from the stack with a hanning kernel a la coppafish. The kernel is the sum of a negative outer circle and a positive inner circle.

Parameters:
  • stack (np.array) – Stack to filter, either X x Y x Ch or X x Y x Ch x Round

  • r1 (int, optional) – Radius in pixels of central positive hanning convolve kernel. Defaults to 2.

  • r2 (int, optional) – Radius in pixels of outer negative hanning convolve kernel. Defaults to 4.

  • dtype (str, optional) – Datatype for performing the computation

Returns:

Filtered stack.

Return type:

np.array

iss_preprocess.image.correction.tilestats_and_mean_image(data_folder, prefix='', suffix='', n_batch=1, black_level=0, max_value=10000, verbose=False, median_filter_size=None, gaussian_filter_size=None, normalise=False, combine_tilestats=False, exclude_tiffs=None, row_filter=None)

Compute tile statistics and mean image to use for illumination correction.

Parameters:
  • data_folder (str) – directory containing images

  • prefix (str, optional) – prefix to filter images to average. Defaults to “”, no filter

  • suffix (str, optional) – suffix to filter images to average. Defaults to “”, no filter

  • n_batch (int, optional) – If 1 average everything, otherwise makes n_batch averages and take the median of those. All averages must fit in RAM. If None, create as many batches as tiffs. Defaults to 1.

  • black_level (float, optional) – image black level to subtract before calculating each mean image. Defaults to 0

  • max_value (float, optional) – image values are clipped to this value after black level subtraction. This reduces the effect of extremely bright features skewing the average image. Defaults to 10000.

  • verbose (bool, optional) – whether to report on progress. Defaults to False

  • median_filter (int, optional) – size of median filter to apply to the correction image. If None, no median filtering is applied. Defaults to None.

  • mean_filter (int, optional) – size of mean filter to apply to the correction image. If None, no mean filtering is applied. Defaults to None.

  • normalise (bool, optional) – Divide each channel by its maximum value. Default to False

  • combine_tilestats (bool, optional) – If False, compute tilestats, if True, load already created tilestats for each tif and sum them.

  • exclude_tiffs (list, optional) – List of str filter to exclude tiffs from average

  • row_filter (str, optional) – If “even”/”odd”, only average tiffs on even/odd rows

Returns:

correction image dict: tile statistics of clipped and black subtracted images

Return type:

numpy.ndarray

iss_preprocess.image.correction.unmix_images(background_image: ndarray, mixed_signal_image: ndarray, coef: float, intercept: float, background_coef: float = 1.0, offset: float = 10.0)

Unmixes two images

One must contain only background autofluorescence and another with both background and useful signal.

Parameters:
  • background_image – numpy array of the background image.

  • mixed_signal_image – numpy array of the image with both signal and background.

  • coef – Coefficient to multiply the background image by before subtraction.

  • intercept – Intercept of the linear model used for unmixing.

  • background_coef – Fudge factor to increase the amount of background subtracted. Default 1.0.

  • offset – Small value to add to the signal image to avoid negative values after subtraction. Default 10.0.

Returns:

The isolated signal image after background subtraction.

Return type:

signal_image

iss_preprocess.image.fstack module

iss_preprocess.image.fstack.fstack(im, wsize=9, alpha=0.2, sth=13, focus=None)
iss_preprocess.image.fstack.fstack_channels(im, wsize=9, alpha=0.2, sth=13, focus=None)
iss_preprocess.image.fstack.gauss3P(x, Y)

Fast 3-point gaussian interpolation

Rewritten based on equations in “Shape from Focus”, Shree K. Nayar, 1989

iss_preprocess.image.fstack.gfocus(im, wsize)

Calculate focus measure as the local variance of the images

Module contents