dcnum.segm.segmenter
Attributes
Exceptions
Initialize self. See help(type(self)) for accurate signature. |
Classes
Base segmenter class |
Functions
|
Make sure a labeling array is returned |
Return dictionary of available segmenters |
Module Contents
- dcnum.segm.segmenter.cv2
- dcnum.segm.segmenter.ndi
- dcnum.segm.segmenter.STRUCTURING_ELEMENT
- exception dcnum.segm.segmenter.SegmenterNotApplicableError(segmenter_class, reasons_list)[source]
Bases:
BaseExceptionInitialize self. See help(type(self)) for accurate signature.
- reasons_list
- segmenter_class
- class dcnum.segm.segmenter.Segmenter(*, kwargs_mask: dict | None = None, debug: bool = False, **kwargs)[source]
Bases:
abc.ABCBase segmenter class
This is the base segmenter class for the multiprocessing operation segmenter
segmenter_mpo.MPOSegmenter(multiple subprocesses are spawned and each of them works on a queue of images) and the single-threaded operation segmentersegmenter_sto.STOSegmenter(e.g. for batch segmentation on a GPU).- Parameters:
kwargs_mask (dict) – Keyword arguments for mask post-processing (see process_labels)
debug (bool) – Enable debugging mode (e.g. CPU segmenter runs in one thread)
kwargs – Additional, optional keyword arguments for segment_batch.
- hardware_processor = 'none'
Required hardware (“cpu” or “gpu”) defined in first-level subclass.
- mask_postprocessing = True
Whether to enable mask post-processing. If disabled, you should make sure that your mask is properly defined and cleaned or you have to call process_labels in your
segment_algorithmimplementation.
- mask_default_kwargs
Default keyword arguments for mask post-processing. See process_labels for available options.
- requires_background_correction = False
Whether the segmenter requires a background-corrected image
- debug = False
- logger
- kwargs
custom keyword arguments for the subclassing segmenter
- kwargs_mask
keyword arguments for mask post-processing
- get_ppid()[source]
Return a unique segmentation pipeline identifier
The pipeline identifier is universally applicable and must be backwards-compatible (future versions of dcnum will correctly acknowledge the ID).
The segmenter pipeline ID is defined as:
KEY:KW_APPROACH:KW_MASK
Where KEY is e.g. “legacy” or “watershed”, and KW_APPROACH is a list of keyword arguments for
segment_algorithm, e.g.:thresh=-6^blur=0
which may be abbreviated to:
t=-6^b=0
KW_MASK represents keyword arguments for process_labels.
- classmethod get_ppid_from_ppkw(kwargs, kwargs_mask=None)[source]
Return the pipeline ID from given keyword arguments
See also
get_ppidSame method for class instances
- static process_labels(labels, *, clear_border: bool = True, fill_holes: bool = True, closing_disk: int = 5)[source]
Post-process retrieved mask image
This is an optional convenience method that is called for each subclass individually. To enable mask post-processing, set mask_postprocessing=True in the subclass and specify default mask_default_kwargs.
- Parameters:
labels (2d uint16 or boolean ndarray) – Labeled input (contains blobs consisting of unique numbers)
clear_border (bool) – clear the image boarder using an equivalent of
skimage.segmentation.clear_border()fill_holes (bool) – binary-fill-holes in the binary mask image using
scipy.ndimage.binary_fill_holes()closing_disk (int or None) – if > 0, perform a binary closing with a disk of that radius in pixels
- static segment_algorithm(image) numpy.ndarray[source]
- Abstractmethod:
The segmentation algorithm implemented in the subclass
Perform segmentation and return boolean mask image
- segment_algorithm_wrapper()[source]
Wraps
self.segment_algorithmto only accept an imageThe static method
self.segment_algorithmmay optionally accept keyword argumentsself.kwargs. This wrapper returns the wrapped method that only accepts the image as an argument. This makes sense if you want to unify
- abstractmethod segment_batch(images, bg_off=None)[source]
Return the bollean mask for an entire batch
This is implemented in the MPO and STO segmenters.
- segment_batch_with_labeling(images, bg_off=None)[source]
Return the processed label image for an image batch
This is intended for testing only. The logic pipeline uses UniversalWorkers to perform labeling and label processing.
- segment_chunk(chunk: int, slot_list: list)[source]
Segment the image data of one ChunkSlot
This is a wrapper for segment_batch. The image information are extracted from the chunk_slot.image/chunk_slot.image_corr properties and the boolean mask arrays are written to ``chunk_slot.mask`.
- Parameters:
chunk_slot (ChunkSlot) – The data chunk to perform segmentation on
- Returns:
mask – The chunk_slot.mask numpy view on the shared mask array.
- Return type:
np.array
- abstractmethod segment_single(image, bg_off: float | None = None)[source]
Return the boolean mask for one image
This is implemented in the MPO and STO segmenters.
- segment_single_with_labeling(image, bg_off=None)[source]
Return the processed label image for one image
This is intended for testing only. The logic pipeline uses UniversalWorkers to perform labeling and label processing.
- classmethod validate_applicability(segmenter_kwargs: dict, meta: dict | None = None, logs: dict | None = None)[source]
Validate the applicability of this segmenter for a dataset
- Parameters:
segmenter_kwargs (dict) – Keyword arguments for the segmenter
meta (dict) – Dictionary of metadata from an
hdf5_data.HDF5Datainstancelogs (dict) – Dictionary of logs from an
hdf5_data.HDF5Datainstance
- Returns:
applicable – True if the segmenter is applicable to the dataset
- Return type:
bool
- Raises:
SegmenterNotApplicableError – If the segmenter is not applicable to the dataset