mrbles.core module

Core Classes and Functions

This file stores the core classes and functions for the MRBLEs Analysis module.

class mrbles.core.Classify(target, sigma=1e-05, train=False, **kwargs)[source]

Bases: future.types.newobject.newobject

Classification of beads by Gaussian Mixture Model.

Parameters:
  • target (list, NumPy array) – List of target ratios.
  • tol (float) – Tolerance. Defaults to 1e-5.
  • min_covar (float) – Minimum covariance. Defaults to 1e-7.
  • sigma (float) – … Defaults to 1e-5.
  • train (boolean) – Sets training mode. Remembers covariance matrix or resets to initial covariance matrix. Defaults to False.
code_metrics(nsigma=3, resolution=100)[source]

Return code metrics.

decode(data)[source]

Decode mrbles.

ellipsoids(nsigma, resolution=100)[source]

Create CI ellipsoids.

found

Return found codes.

init_covars

Return initial covariance matrix.

init_weights

Return initial weights.

log_prob

Return log probabilities.

means

Return means.

missing

Return missing codes.

output

Return codes, probability and log probability.

probs

Return probabilities.

stds

Return Choleski based SD.

static unit_sphere(resolution=100)[source]

Return unit sphere.

class mrbles.core.FindBeadsCircle(min_r, max_r, param_1=10, param_2=10, annulus_width=2, min_dist=None, enlarge=1, auto_filt=True, border_clear=False, parallelize=True)[source]

Bases: mrbles.core.FindBeadsImaging

Find and identify bead objects from image.

Parameters changes for each setup/magnification/bead-set.

Parameters:
  • min_r (int) – Sets the minimum diameter of the bead in pixels.
  • max_r (int) – Sets the maximum diameter of the bead in pixels.
  • param_1 (int) – Sets the gradient steepness. CHECK
  • param_2 (int) – Sets the sparsity. CHECK
  • annulus_width (int, optional) – Sets the width of the annulus in pixels. Defaults to 2 pixels.
  • min_dist (int, optional) – Sets the minimal distance between the centers of the beads in pixels. Defaults to 2x of the minimum diameter (min_r).
  • enlarge (float, optional) – Enlarges the found diameter by this factor. 1 remains equal, 1.1 enlarges by 10% and 0.9 shrinks by 10%. Defaults to 1, no enlarging/shrinking.
static circle_mask(image, min_dist, min_r, max_r, param_1, param_2, enlarge)[source]

Find initial circles using Hough transform and return mask.

static circle_separate(mask, circles)[source]

Find and separate circles using watershed on initial mask.

circles_dim

Return circle dimensions.

static convert(image)[source]

8 Bit Convert.

Checks image data type and converts if necessary to uint8 array. image : M x N image array

create_annulus_mask(labeled_mask)[source]

Create annulus mask from regular mask.

find(image)[source]

Execute finding beads image(s).

labeled_annulus_mask

Return labeled annulus mask.

labeled_mask

Return labeled mask.

overlay_image(image, annulus=None, dim=None)[source]

Overlay image with circles of labeled mask.

class mrbles.core.FindBeadsImaging(bead_size, border_clear=True, circle_size=None, parallelize=False)[source]

Bases: mrbles.data.ImageDataFrame

Find and identify beads and their regions using imaging.

Parallel computing version.

Parameters:
  • bead_size (int) – Approximate width of beads (circles) in pixels.
  • border_clear (boolean) – Beads touching border or ROI will be removed. Defaults to True.
  • circle_size (int) – Set circle size for auto find circular ROI.
Variables:
  • area_min (float) – Sets the minimum area in pixels. Set to minimum size inside of ring. Defaults to 0.1 * area of set bead_size.
  • area_max (float) – Sets the maximum area in pixels. Set maximum size outside of ring. Defaults to 1.5 * area of set bead_size.
  • eccen_max (float) – Get or set maximum eccentricity of beads in value 0 to 1, where a perfect circle is 0. Defaults to 0.65.
area_max

Get or set minimum area of beads (circles) in pixels.

area_min

Get or set minimum area of beads (circles) in pixels.

bead_dims

Return found bead dimensions.

bead_labels

Return all positive labels of labeled mask.

bead_num

Return number of beads labeled mask.

bead_size

Get or set approximate width of beads (circles) in pixels.

static circle_area(diameter)[source]

Return area of circle.

Parameters:diameter (float) – Diameter of circle.
classmethod circle_roi(image, circle_size, hough_settings=None)[source]

Apply a circular image ROI.

Parameters:
  • image (NumPy array image)
  • hough_settings (list, int) – Settings for HoughCircles in list. list[0] = dp, list[1] = param1, list[2] = param2
static cross_overlay(image, dims, color=True)[source]

Create image with overlay crosses.

eccen_max

Get or set maximum eccentricity of beads from 0 to 1.

A perfect circle is 0 and parabola is 1.

static eccentricity(axis_a, axis_b)[source]

Return eccentricity by major axes.

Parameters: axis_a : float

Size major axis a.
axis_b : float
Size major axis b.
classmethod filter_mask(mask, filter_params, filter_names, slice_types, border_clear=False)[source]

Filter labeled mask based on provided parameters.

classmethod filter_properties(properties, filter_params, filter_names, slice_types)[source]

Get labels of areas outside of limits.

static filter_property(properties, filter_param, filter_name, slice_type)[source]

Get labels of beads outside/inside/up/down of propert limits.

Parameters:
  • properties (photutils table) – Table with feature properties from labeled mask. >>> from photutils import source_properties, properties_table >>> tbl = properties_table(properties) >>> properties = source_properties(mask, mask)
  • filter_param (float, int, list) – Parameters to filter by. If provided a list it will filter by range, inside or outside). If provided a value it filter up or down that value.
  • slice_type (string) – ‘outside’ : < > ‘inside’ : >= <= ‘up’ : > ‘down’ : <
find(image)[source]

Execute finding beads image(s).

static get_dimensions(mask)[source]

Get dimensions of labeled regions in labeled mask.

static get_unique_count(mask)[source]

Get count of unique positive values from labeled mask.

static get_unique_values(mask)[source]

Get all unique positive values from labeled mask.

img2bin(image, thr_block=15, thr_c=11)[source]

Convert and adaptive threshold image.

classmethod make_mask_outside(mask, size, buffer=0)[source]

Return labeled mask of area around bead.

mask(mask_type)[source]

Return labeled mask of the specified mask type.

mask_types

Return list of mask types.

static sector_mask(shape, center, radius)[source]

Return a boolean mask for a circular ROI.

static show_image_overlay(image, image_blend, alpha=0.3, cmap1='Greys_r', cmap2='jet')[source]

Overlay of 2 images using alpha blend.

Parameters:
  • image (NumPy array) – Base image.
  • image_blend (NumPy arra) – Image to blend over base image.
  • aplha (float) – Amount of blending. Value between 0 and 1. Defaults to 0.3.
  • c_map1 (cmap) – Color scheme using cmap. See matplotlib for color schemes. Defaults to ‘Greys_r’, which are reversed grey values.
class mrbles.core.ICP(target, matrix_method='std', offset=None, max_iter=100, tol=0.0001, outlier_pct=0.01)[source]

Bases: future.types.newobject.newobject

Iterative Closest Point (ICP).

Iterative Closest Point (ICP) algorithm to minimize the difference between two clouds of points.

Parameters:
  • matrix_method (string/function/list, optional) – Transformation matrix method. Standard methods: ‘max’, ‘mean’, ‘std’. Other options: own function or list of initial guesses. Defaults to ‘std’.
  • offset (list of float, optional)
  • max_iter (int, optional) – Maximum number of iterations. Defaults to 100.
  • tol (float, optional) – Convergence threshold. ICP will stop after delta < tol. Defaults to 1e-4.
  • outlier_pct (float, optional) – Discard percentile 0.x of furthest distance from target. Percentile given in fraction [0-1], e.g. ‘0.001’. Defaults to 0.
  • train (boolean) – Turn on (True) or off (False) traning mode. This will keep the current tranformation from resetting to default initial values. Defaults to True.
  • echo (boolean) – Turn on (True) or off (False) printing information while in process. Prints the delta for each iteration, the final number of iterations, and the final transformation and offset matrices.
Variables:
  • matrix (NumPy array) – This stores the transformation matrix.
  • offset (NumPy vector) – This stores the offset vector.
  • Functions
  • ---------
  • fit (function) – Function to find ICP using set parameters and attributes.
  • transform (function) – Function to apply transformat data using current transformation matrix and offset vector.
fit(data, target=None)[source]

Fit Iterative Closest Point.

static matrix_create(func, input1, input2)[source]

Create identity matrix and set values with function on inputs e.g ‘np.mean’.

Parameters:
  • func (function) – Function to apply on input1 divided by input2, e.g. ‘np.std’. Insert function without function call: ().
  • input1 (list, ndarray)
  • input2 (list, ndarray)
Returns:

matrix – Returns func(input1/input2)

Return type:

ndarray

transform(data=None)[source]

Apply transformation matrix to data.

class mrbles.core.SpectralUnmixing(ref_data)[source]

Bases: mrbles.data.ImageDataFrame

Spectrally unmix images using reference spectra.

Unmix the spectral images to dye images, e.g., 620nm, 630nm, 650nm images to Dy, Sm and Tm nanophospohorous lanthanides using reference spectra for each dye.

Parameters:ref_data (list, ndarray, Pandas DataFrame, mrbles.data.References) – Reference spectra for each dye channel as Numpy Array: N x M, where N are the spectral channels and M the dye channels.
unmix(images)[source]

Unmix images based on initiated reference data.

Unmix the spectral images to dye images, e.g., 620nm, 630nm, 650nm images to Dy, Sm and Tm nanophospohorous lanthanides using reference spectra for each dye.

Parameters:image_data (NumPy array, Xarry DataArray, mrbles.Images) – Spectral images as NumPy array: N x M x P, where N are the spectral channels and M x P the image pixels (Y x X).
mrbles.core.accepts(*types)[source]

Check input parameters for data types.