segmentation#

Segmentation#

class scportrait.pipeline.segmentation.segmentation.Segmentation(config, directory, nuc_seg_name, cyto_seg_name, _tmp_image_path, project_location, debug, overwrite, project, filehandler, from_project: bool = False, dummy: bool = False, **kwargs)#

Bases: ProcessingStep

Segmentation helper class used for creating segmentation workflows.

maps#

Segmentation workflows based on the Segmentation class can use maps for saving and loading checkpoints and perform operations. Maps can be array like structures, e.g. memory-mapped temp arrays.

Type:

dict(str)

DEFAULT_FILTER_ADDTIONAL_FILE#
Type:

str, default filtered_classes.csv

PRINT_MAPS_ON_DEBUG#
Type:

bool, default False

identifier#

Only set if called by ShardedSegmentation. Unique index of the shard.

Type:

int, default None

window#

Only set if called by ShardedSegmentation. Defines the window which is assigned to the shard. The window will be applied to the input. The first element refers to the first dimension of the image and so on. For example use [(0,1000),(0,2000)] To crop the image to 1000 px height and 2000 px width from the top left corner.

Type:

list(tuple), default None

input_path#

Only set if called by ShardedSegmentation. Location of the input hdf5 file. During sharded segmentation the ShardedSegmentation derived helper class will save the input image in form of a hdf5 file. This makes the input image available for parallel reading by the segmentation processes.

Type:

str, default None

Initialize a segmentation step.

Parameters:
  • config – Step configuration.

  • directory – Working directory for this segmentation step.

  • nuc_seg_name – Name of the nucleus segmentation output.

  • cyto_seg_name – Name of the cytosol segmentation output.

  • _tmp_image_path – Path to the temporary input image memmap.

  • project_location – Project root path.

  • debug – Enable verbose logging.

  • overwrite – Whether existing outputs may be overwritten.

  • project – Active project instance when project-managed.

  • filehandler – Shared SpatialData file handler.

  • from_project – Whether this step is invoked from a project-managed context.

  • dummy – If True, initialize without cleaning the existing log file. This is used for side-effect-free helper instances that only inspect configuration-derived state.

process(input_image)#

Process the input image with the segmentation method.

ShardedSegmentation#

class scportrait.pipeline.segmentation.segmentation.ShardedSegmentation(*args, **kwargs)#

Bases: Segmentation

Perform segmentation on overlapping image tiles and stitch the results back together.

A lightweight dummy workflow instance is created during initialization to determine which input channels need to be loaded without mutating the main step log.

Initialize a segmentation step.

Parameters:
  • config – Step configuration.

  • directory – Working directory for this segmentation step.

  • nuc_seg_name – Name of the nucleus segmentation output.

  • cyto_seg_name – Name of the cytosol segmentation output.

  • _tmp_image_path – Path to the temporary input image memmap.

  • project_location – Project root path.

  • debug – Enable verbose logging.

  • overwrite – Whether existing outputs may be overwritten.

  • project – Active project instance when project-managed.

  • filehandler – Shared SpatialData file handler.

  • from_project – Whether this step is invoked from a project-managed context.

  • dummy – If True, initialize without cleaning the existing log file. This is used for side-effect-free helper instances that only inspect configuration-derived state.

process(input_image)#

Process the input image with the sharded segmentation method.

Important

This function is called automatically when a Segmentation Class is executed.

Parameters:

input_image (np.array) – Input image to be processed. The input image should be a numpy array of shape (C, H, W) where C is the number of channels, H is the height of the image and W is the width of the image.

complete_segmentation(input_image, force_run=False)#

Complete an already started sharded segmentation of the provided input image.

Parameters:
  • input_image (np.array) – Input image to be processed. The input image should be a numpy array of shape (C, H, W) where C is the number of channels, H is the height of the image and W is the width of the image.

  • force_run (bool) – If set to True the segmentation will be run even if a completed segmentation is already found in the sdata object. Default is False.