magmap.cv.classifier module¶
Blob classifier.
- class magmap.cv.classifier.ClassifyImage[source]¶
Bases:
objectConvert 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: thesubimg_offsetargument 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:
model_path (
Optional[str], default:None) – Path to Keras model. Defaults to None, in which casemagmap.settings.config.classifieris accessed.image5d (
Optional[ndarray], default:None) – Image int, z, y, x, [c]order. Defaults to None, in which casemagmap.settings.config.img5d.imgis accessed.channels (
Optional[Sequence[int]], default:None) – Sequence of channels inimage5d. Defaults to None, in which casemagmap.settings.config.chanelis accessed.blobs (
Optional[Blobs], default:None) – Blobs instance. Defaults to None, in which casemagmap.settings.config.blobsis accessed.kwargs – Additional arguments to
classify_blobs().
- Raises:
found. –
- 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 int, z, y, x, [c]order.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 tosubimg_offset; defaults to False.
- Returns:
blobs_mask: row mask for blobs in sub-image.classifications: corresponding blob classifications.
- Return type:
Tuple of
- Raises:
- magmap.cv.classifier.classify_patches(model, x, thresh=0.5)[source]¶
Classify patches with a model.
- Parameters:
- 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:
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:
- Returns:
roi: region of interest asz, y, x, [c]blobs_roi_mask: mask forblobsin the ROI.blobs_shift: Offset of blobs relative tosubimg_offset.
- Return type:
Tuple of