dcnum.segm.segmenter_mpo

Attributes

mp_spawn

Classes

MPOSegmenter

Segmenter with multiprocessing operation

MPOSegmenterWorker

Worker process for CPU-based segmentation

MPOSegmenterWorkerProcess

Worker process for CPU-based segmentation

MPOSegmenterWorkerThread

Worker process for CPU-based segmentation

Module Contents

dcnum.segm.segmenter_mpo.mp_spawn = None
class dcnum.segm.segmenter_mpo.MPOSegmenter(*, num_workers: int | None = None, kwargs_mask: dict | None = None, debug: bool = False, **kwargs)[source]

Bases: dcnum.segm.segmenter.Segmenter, abc.ABC

Segmenter with multiprocessing operation

Parameters:
  • num_workers – Number of workers (processes) to spawn

  • kwargs_mask (dict) – Keyword arguments for mask post-processing (see process_labels)

  • debug (bool) – Debugging parameters

  • kwargs – Additional, optional keyword arguments for segment_algorithm defined in the subclass.

hardware_processor = 'cpu'

Required hardware (“cpu” or “gpu”) defined in first-level subclass.

num_workers
slot_list = None

List of ChunkSlot instances

mp_slot_index

The slot that is currently being worked on

mp_active

Event that defines whether the workers are allowed to do work

mp_num_workers_done

Number of workers that are done processing the slot

mp_shutdown

Shutdown event tells workers to stop when set to != 0

_worker_starter = None
_workers = []
__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
__getstate__()[source]
__setstate__(state)[source]
join_workers()[source]

Ask all workers to stop and join them

reinitialize_workers(slot_list)[source]
segment_batch(images: numpy.ndarray, bg_off: numpy.ndarray | None = None)[source]

Perform batch segmentation of images

Before segmentation, an optional background offset correction with bg_off is performed. After segmentation, mask postprocessing is performed according to the segmenter class definition.

Parameters:
  • images (3d np.ndarray of shape (N, Y, X)) – The time-series image data. First axis is time.

  • bg_off (1D np.ndarray of length N) – Optional 1D numpy array with background offset

Notes

  • If the segmentation algorithm only accepts background-corrected images, then images must already be background-corrected, except for the optional bg_off.

segment_chunk(chunk: int, slot_list: list)[source]

Segment the image data of one ChunkSlot

Parameters:
  • chunk – The data chunk index to perform segmentation on

  • slot_list – List of ChunkSlotData instances (e.g. SlotRegister.slots)

Returns:

mask – The chunk_slot.mask numpy view on the shared boolean mask array.

Return type:

np.array

segment_single(image, bg_off: float | None = None)[source]

Return the boolean mask image for an input image

Before segmentation, an optional background offset correction with bg_off is performed. After segmentation, mask postprocessing is performed according to the class definition.

close()[source]

Subclasses can implement clean-up code here

class dcnum.segm.segmenter_mpo.MPOSegmenterWorker(segmenter, sl_start: int, sl_stop: int)[source]

Worker process for CPU-based segmentation

Parameters:
  • segmenter (.segmenter_mpo.MPOSegmenter) – The segmentation instance

  • sl_start (int) – Start of slice of input array to process

  • sl_stop (int) – Stop of slice of input array to process

segmenter
slot_list

List of ChunkSlot instances

mp_slot_index

The slot that is currently being worked on

mp_active

Whether the workers are allowed to do work

mp_num_workers_done

Number of workers that are done processing the slot

mp_shutdown

Shutdown bit tells workers to stop when set to != 0

sl_start
sl_stop
run()[source]
class dcnum.segm.segmenter_mpo.MPOSegmenterWorkerProcess(*args, **kwargs)[source]

Bases: MPOSegmenterWorker, mp_spawn

Worker process for CPU-based segmentation

Parameters:
  • segmenter (.segmenter_mpo.MPOSegmenter) – The segmentation instance

  • sl_start (int) – Start of slice of input array to process

  • sl_stop (int) – Stop of slice of input array to process

start()[source]

Start child process

class dcnum.segm.segmenter_mpo.MPOSegmenterWorkerThread(*args, **kwargs)[source]

Bases: MPOSegmenterWorker, threading.Thread

Worker process for CPU-based segmentation

Parameters:
  • segmenter (.segmenter_mpo.MPOSegmenter) – The segmentation instance

  • sl_start (int) – Start of slice of input array to process

  • sl_stop (int) – Stop of slice of input array to process