Operations

Operation is the parent class for all the operations above.

class celltk.core.operation.Operation(images=[], masks=[], arrays=[], output='out', save=True, force_rerun=False, _output_id=None, _split_key='&')

Base class for all other Operations.

Parameters
  • images (Collection[str], default: []) – Names of images to use in this operation

  • masks (Collection[str], default: []) – Names of masks to use in this operation

  • arrays (Collection[str], default: []) – Names of arrays to use in this operation

  • output (str, default: 'out') – Name to save the output stack

  • save (bool, default: True) – If False, the final result will not be saved to disk.

  • force_rerun (bool, default: False) – If True, all functions are run even if the output stack is already loaded.

  • _output_id (Optional[Tuple[str]], default: None) – Private attribute used to track output from the Operation.

  • _split_key (str, default: '&') – Used to specify outputs from functions that return multiple outputs. For example, if you align two channels the outputs will be saved as ‘align&channel000’ and ‘align&channel001’ for _split_key = ‘&’

__call__(images=[], masks=[], arrays=[], _return_keys=False)

__call__ runs operation independently of Pipeline class

Parameters
  • images (Collection[Image], default: []) –

  • masks (Collection[Mask], default: []) –

  • arrays (Collection[Array], default: []) –

  • _return_keys (bool, default: False) –

Return type

Union[Image, Mask, Array]

add_function(func, *, save_as=None, output_type=None, **kwargs)

Adds a function to be run by the Operation

Parameters
  • func (str) – Name of the function. Must exist in the Operation class.

  • save_as (Optional[str], default: None) – Name to save the result as. If not set, will not be saved unless it is the last function and Operation.save is True.

  • output_type (Optional[str], default: None) – If given, changes the default output type to another CellTK type (i.e iimage, mask, track)

Pararm kwargs

All other kwargs are passed to the function. Note that they must be provided as kwargs.

Return type

None

Returns

None

apply_mask(image, mask=None, mask_name=None, *args, **kwargs)

Applies a boolean mask to an image. User can supply a boolean mask or the name of a function from filter_utils.

Parameters
  • image (Image) – Image to be masked

  • mask (Optional[Mask], default: None) – Boolean mask of same shape as image

  • mask_name (Optional[str], default: None) – Name of a function in filter_utils to use to create a boolean mask. If given, any input mask is ignored

  • args – Passed to mask_name function

  • kwargs – Passed to mask_name function.

Return type

Stack

Returns

Masked image

binary_threshold(image, lower=None, upper=None, inside=None, outside=None)

This function is too much. Write a simpler binarize function This is more like constant_thres w/o label as is.

Parameters
  • image (Image) –

  • lower (Optional[float], default: None) –

  • upper (Optional[float], default: None) –

  • inside (Optional[float], default: None) –

  • outside (Optional[float], default: None) –

Return type

Image

get_inputs_and_outputs()

Returns all possible inputs and outputs expected by the Operation. Not all will be made or used. Typically this function is used by Pipeline to determine which files to load.

Note

  • This function is expected to change soon in a new version.

Return type

List[List[tuple]]

image_to_mask(image)

Convert an Image stack to a Mask stack.

Parameters

image (Image) – Image stack to be typed as a Mask

Return type

Mask

Returns

Input stack with Mask designation.

invert(image, signed_float=False)

Inverts the intensity of the given image. Wrapper for skimage.util.invert.

Parameters
  • image (Image) – Image to be inverted.

  • signed_float (bool, default: False) – Set to True if _______________

Return type

Image

make_boolean_mask(image, mask_name='outside', *args, **kwargs)

Generates a mask using a function from filter_utils.

Parameters
  • image (Image) – Image to use for generating mask

  • mask_name (str, default: 'outside') – Name of the function in filter_utils

  • args – Passed to mask_name function

  • kwargs – Passed to mask_name function.

Return type

Mask

Returns

Boolean mask with same shape as input image

mask_to_image(mask)

Convert a Mask stack to a Image stack.

Parameters

mask (Mask) – Mask stack to be typed as a Image

Return type

Image

Returns

Input stack with Image designation.

mask_to_seeds(mask)

Create seed points at the centroid of each object in mask.

Parameters

mask (Mask) – Mask to serve as template

Return type

Mask

Returns

Mask of same shape as input mask with the pixel corresponding to the centroid of each object labeled.

match_labels_linear(dest, source)

Transfers labels from source mask to dest mask based on maximizing the area overlap. Objects with no overlap are given a new label starting at max_label_value + 1.

Parameters
  • dest (Mask) – Mask with objects to be labeled

  • source (Mask) – Mask with labeled objects to use as template

Return type

Mask

Returns

Labeled mask

regular_seeds(image, n_points=25, dtype=<class 'numpy.uint8'>)

Labels an arbitrary number of approximately evenly-spaced pixels with unique integers.

Parameters
  • image (Image) – Images to serve as template for making seed mask

  • n_points (int, default: 25) – Number of pixels to label

  • dtype (type, default: <class 'numpy.uint8'>) – Data type of the output array.

Return type

Mask

Returns

Mask of same shape as image with n_points pixels labeled with a unique integer.

run_operation(inputs, _return_inputs=True)

Sets up a generator to run the operation and return results for each function in turn. This function also handles naming and typing the outputs of each function. Typically used by Pipeline. To use an Operation on arrays and get arrays in return, preferably use the __call__ method instead.

Parameters
  • inputs (ImageContainer) – ImageContainer with all of the inputs required by the Operation.

  • _return_inputs (bool, default: True) –

Return type

Generator

Returns

A signle generator for the results of each function.

set_logger(logger)

Add a custom logger object to log Pipeline operation.

Parameters

logger (Logger) – Custom logging object. Must be type logging.Logger.

Return type

None

Returns

None