magmap.cv.classifier module

Blob classifier.

class magmap.cv.classifier.ClassifyImage[source]

Bases: object

Convert a label to an edge with class methods as an encapsulated way to use in multiprocessing without requirement for global variables.

blobs = None
classmethod classify_chunk(model_path, subimg_offset, subimg_size, channels, **kwargs)[source]

Classify blobs in an image chunk.

Parameters:
Returns:

  • subimg_offset: the subimg_offset argument to track during multiprocessing.

  • blobs_mask: row mask for blobs in sub-image.

  • classifications: corresponding blob classifications.

Return type:

Tuple of

classmethod classify_whole_image(model_path=None, image5d=None, channels=None, blobs=None, **kwargs)[source]

Classify blobs in the whole image through multiprocessing

Parameters:
Raises:
image5d = None
magmap.cv.classifier.classify_blobs(path, image5d, subimg_offset, subimg_size, channels, blobs, patch_size=16, blobs_relative=False)[source]

Classify blobs based on surrounding image patches.

Parameters:
  • path (str) – Path to Keras model.

  • image5d (ndarray) – Image in t, z, y, x, [c] order.

  • subimg_offset (Sequence[int]) – Subimage offset in z, y, x.

  • subimg_size (Sequence[int]) – Subimage size in z, y, x.

  • channels (Sequence[int]) – Sequence of channels in image5d.

  • blobs (Blobs) – Blobs instance.

  • patch_size (int, default: 16) – Patch size as an int for both width and height; defaults to 16.

  • blobs_relative (default: False) – True to treat blob coordinates as relative to subimg_offset; defaults to False.

Returns:

  • blobs_mask: row mask for blobs in sub-image.

  • classifications: corresponding blob classifications.

Return type:

Tuple of

Raises:

ModuleNotFoundError

magmap.cv.classifier.classify_patches(model, x, thresh=0.5)[source]

Classify patches with a model.

Parameters:
  • model – Keras model.

  • x (ndarray) – 2D array of image patches, each in y, x, c format.

  • thresh (float, default: 0.5) – Score threshold to classify as 1, otherwise 0. Defaults to 0.5.

Returns:

  • y_pred: Integer array of class predictions.

  • y_score: Float array of raw prediction scores.

Return type:

Tuple of

magmap.cv.classifier.extract_patches(roi, blobs, size=16)[source]

Extract image patches for blobs.

Patches are 2D, centered on each blob but offset by one pixel in width and height for even-numbered patch dimensions.

Parameters:
  • roi (ndarray) – Image region of interst as a 3/4D array (z, y, x, [c]).

  • blobs (ndarray) – 2D blobs array with each blob as a row in z, y, x, ....

  • size (int, default: 16) – Patch size as an int for both width and height; defaults to 16.

Returns:

magmap.cv.classifier.setup_classification_roi(image5d, subimg_offset, subimg_size, blobs, patch_size, blobs_relative=False)[source]

Set up ROI for blob classification.

Sets up an image ROI with a border to provide uniformly sized image patches around blobs, including blobs on the ROI edge. If the border would exceed an edge of the image, a padding area is created where blobs are excluded so that edge blobs can still have the full-sized patches.

Parameters:
  • image5d (ndarray) – 4/5D array as t, z, y, x[, c].

  • subimg_offset (Sequence[int]) – Subimage offset in z, y, x.

  • subimg_size (Sequence[int]) – Subimage size in z, y, x.

  • blobs (Blobs) – Blobs instance.

  • patch_size (int) – Patch size as an int for both width and height.

  • blobs_relative (bool, default: False) – True if blobs coordinates are relative; defaults to False.

Returns:

  • roi: region of interest as z, y, x, [c]

  • blobs_roi_mask: mask for blobs in the ROI.

  • blobs_shift: Offset of blobs relative to subimg_offset.

Return type:

Tuple of