dacapo.utils.pipeline

Classes

CreatePoints

A batch filter that creates random points in a 3D label volume.

MakeRaw

A batch filter that generates a raw image from labels.

DilatePoints

A batch filter that performs dilation on labeled points.

RandomDilateLabels

A batch filter that randomly dilates labels in a batch.

Relabel

A batch filter that relabels the labels in a batch.

ExpandLabels

A batch filter that expands labels by assigning the nearest label to each pixel within a specified distance.

ZerosSource

A batch provider that generates arrays filled with zeros.

Functions

random_source_pipeline([voxel_size, input_shape, ...])

Create a random source pipeline and batch request for example training.

Module Contents

class dacapo.utils.pipeline.CreatePoints(labels, num_points=(20, 150))

A batch filter that creates random points in a 3D label volume.

labels

The key of the label data in the batch.

Type:

str

num_points

A tuple specifying the range of the number of points to create.

Type:

tuple

process()

Create random points in the label volume.

labels
num_points
process(batch, request)

Process the batch by creating random points in the label volume.

Parameters:
  • batch (dict) – The input batch containing label data.

  • request (gp.BatchRequest) – The batch request.

Raises:

ValueError – If the number of points is not an integer.

Examples

>>> CreatePoints.process(batch, request)
class dacapo.utils.pipeline.MakeRaw

A batch filter that generates a raw image from labels.

raw

The key of the raw data in the batch.

Type:

str

labels

The key of the label data in the batch.

Type:

str

gaussian_noise_args

A tuple specifying the mean and standard deviation of the Gaussian noise.

Type:

tuple

gaussian_noise_lim

The limit of the Gaussian noise.

Type:

float

gaussian_blur_args

A tuple specifying the mean and standard deviation of the Gaussian blur.

Type:

tuple

membrane_like

A boolean indicating whether to generate a membrane-like structure.

Type:

bool

membrane_size

The size of the membrane-like structure.

Type:

int

inside_value

The value to set inside the membranes of objects.

Type:

float

setup()

Set up the batch filter by defining the specification of the raw image.

process()

Generate the raw image from the labels.

class Pipeline(raw, labels, gaussian_noise_args: Iterable = (0.5, 0.1), gaussian_noise_lim: float = 0.3, gaussian_blur_args: Iterable = (0.5, 1.5), membrane_like=True, membrane_size=3, inside_value=0.5)
raw
labels
gaussian_noise_args
gaussian_noise_lim
gaussian_blur_args
membrane_like
membrane_size
inside_value
setup()

Set up the batch filter by defining the specification of the raw image.

Raises:

ValueError – If the data type is not float32.

Examples

>>> MakeRaw.setup()
process(batch, request)

Process the batch by generating the raw image from the labels.

Parameters:
  • batch (gp.Batch) – The input batch.

  • request (gp.BatchRequest) – The request for the output batch.

Returns:

The output batch.

Return type:

gp.Batch

Raises:

ValueError – If the data type is not float32.

Examples

>>> MakeRaw.process(batch, request)
class dacapo.utils.pipeline.DilatePoints(labels, dilations=[2, 8])

A batch filter that performs dilation on labeled points.

labels

The key of the labels data in the batch.

Type:

str

dilations

A list of two integers representing the range of dilations to apply.

Type:

list[int]

process()

Perform dilation on the labeled points.

labels
dilations
process(batch, request)

Process the batch by performing dilation on the labeled points.

Parameters:
  • batch (Batch) – The input batch.

  • request (Request) – The request object.

Raises:

ValueError – If the dilations are not integers.

Examples

>>> DilatePoints.process(batch, request)
class dacapo.utils.pipeline.RandomDilateLabels(labels, dilations=[2, 8])

A batch filter that randomly dilates labels in a batch.

labels

The key of the labels in the batch.

Type:

str

dilations

A list of two integers representing the range of dilations.

Type:

list[int]

process()

Randomly dilate the labels in the batch.

labels
dilations
process(batch, request)

Process the batch by randomly dilating labels.

Parameters:
  • batch (dict) – The input batch.

  • request – The request object.

Raises:

ValueError – If the dilations are not integers.

Examples

>>> RandomDilateLabels.process(batch, request)
class dacapo.utils.pipeline.Relabel(labels, connectivity=1)

A batch filter that relabels the labels in a batch.

Parameters:
  • labels (str) – The name of the labels data in the batch.

  • connectivity (int, optional) – The connectivity used for relabeling. Defaults to 1.

process()

Process the batch and relabel the labels.

labels
connectivity
process(batch, request)

Process the batch and relabel the labels.

Parameters:
  • batch (Batch) – The input batch.

  • request (Request) – The request for processing.

Returns:

The output batch.

Return type:

Batch

Raises:

ValueError – If the connectivity is not an integer.

Examples

>>> Relabel.process(batch, request)
class dacapo.utils.pipeline.ExpandLabels(labels, background=0)

A batch filter that expands labels by assigning the nearest label to each pixel within a specified distance.

labels

The name of the labels data in the batch.

Type:

str

background

The label value representing the background.

Type:

int

process()

Process the batch and expand the labels.

labels
background
process(batch, request)

Process the batch by expanding the labels.

Parameters:
  • batch (gp.Batch) – The input batch.

  • request (gp.BatchRequest) – The batch request.

Raises:

ValueError – If the background is not an integer.

Examples

>>> ExpandLabels.process(batch, request)
class dacapo.utils.pipeline.ZerosSource(key, spec)

A batch provider that generates arrays filled with zeros.

key

The key to use for the generated array.

Type:

str

_spec

A dictionary containing the specification of the array.

Type:

dict

setup()

Perform any necessary setup before providing batches.

provide()

Provide a batch containing an array filled with zeros.

key
setup()

Perform any necessary setup before providing batches.

Raises:

NotImplementedError – If the method is not implemented.

Examples

>>> ZerosSource.setup()
provide(request)

Provide a batch containing an array filled with zeros.

Parameters:

request (gp.BatchRequest) – The request for the batch.

Returns:

The provided batch.

Return type:

gp.Batch

Raises:

NotImplementedError – If the method is not implemented.

Examples

>>> ZerosSource.provide(request)
dacapo.utils.pipeline.random_source_pipeline(voxel_size=(8, 8, 8), input_shape=(148, 148, 148), dtype=np.uint8, expand_labels=False, relabel_connectivity=1, random_dilate=True, num_points=(20, 150), gaussian_noise_args=(0, 0.1), gaussian_blur_args=(0.5, 1.5), membrane_like=True, membrane_size=3, inside_value=0.5)

Create a random source pipeline and batch request for example training.

Parameters:
  • voxel_size (tuple of int) – The size of a voxel in world units.

  • input_shape (tuple of int) – The shape of the input arrays.

  • dtype (numpy.dtype) – The dtype of the label arrays.

  • expand_labels (bool) – Whether to expand the labels into the background.

  • relabel_connectivity (int) – The connectivity used for for relabeling.

  • random_dilate (bool) – Whether to randomly dilate the individual labels.

  • num_points (tuple of int) – The range of the number of points to add to the labels.

  • gaussian_noise_args (tuple of float) – The mean and standard deviation of the Gaussian noise to add to the raw array.

  • gaussian_blur_args (tuple of float) – The mean and standard deviation of the Gaussian blur to apply to the raw array.

  • membrane_like (bool) – Whether to generate a membrane-like structure in the raw array.

  • membrane_size (int) – The width of the membrane-like structure on the outside of the objects.

  • inside_value (float) – The value to set inside the membranes of objects.

Returns:

The batch generating Gunpowder pipeline. gunpowder.BatchRequest: The batch request for the pipeline.

Return type:

gunpowder.Pipeline

Raises:

ValueError – If the input_shape is not an integer.

Examples

>>> random_source_pipeline(voxel_size=(8, 8, 8), input_shape=(148, 148, 148), dtype=np.uint8, expand_labels=False,
>>>                        relabel_connectivity=1, random_dilate=True, num_points=(20, 150), gaussian_noise_args=(0, 0.1),
>>>                        gaussian_blur_args=(0.5, 1.5), membrane_like=True, membrane_size=3, inside_value=0.5)