segmentation#

Segmentation#

class scportrait.pipeline.segmentation.Segmentation(config, directory, nuc_seg_name, cyto_seg_name, _tmp_image_path, project_location, debug, overwrite, project, filehandler, **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. Maps can be numpy 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

Example

def process(self):
    # two maps are initialized
    self.maps = {"map0": None, "map1": None}

    # its checked if the segmentation directory already contains these maps and they are then loaded. The index of the first map which has not been found is returned. It indicates the step where computation needs to resume
    current_step = self.load_maps_from_disk()

    if current_step <= 0:
        # do stuff and generate map0
        self.save_map("map0")

    if current_step <= 1:
        # do stuff and generate map1
        self.save_map("map1")
save_map(map_name)#

Saves newly computed map.

Args

map_name (str): name of the map to be saved, as defined in self.maps.

Example

# declare all intermediate maps
self.maps = {"myMap": None}

# load intermediate maps if possible and get current processing step
current_step = self.load_maps_from_disk()

if current_step <= 0:
    # do some computations

    self.maps["myMap"] = myNumpyArray

    # save map
    self.save_map("myMap")
process(input_image)#

Process the input image with the segmentation method.

ShardedSegmentation#

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

Bases: Segmentation

To perform a sharded segmentation where the input image is split into individual tiles (with overlap) that are processed idnividually before the results are joined back together.

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.