Skip to content

Patch Construction

Source

Patch construction protocol and default/lateral-context constructors.

PatchConstructor

Bases: Protocol

A callable that modifies how patches are constructed in the PatchExtractor.

This protocol defines the signature of a callable that is passed as an argument to the PatchExtractor. It can be used to modify how patches are constructed, for example creating patches with multiple lateral context levels for MicroSplit.

__call__(image_stack, sample_idx, channels, coords, patch_size)

Build a single patch from an image stack at the given sample and coords.

Parameters:

  • image_stack (ImageStack) –

    The image stack to construct a patch from.

  • sample_idx (int) –

    Sample index. The first dimension of the image data will be indexed at this value.

  • channels (sequence of int or None) –

    Channel indices to use; None for all channels.

  • coords (sequence of int) –

    The coordinates that define the start of a patch.

  • patch_size (sequence of int) –

    The size of the patch in each spatial dimension.

Returns:

  • ndarray

    The patch.

default_patch_constr(image_stack, sample_idx, channels, coords, patch_size)

Extract a single patch from the image stack (default constructor).

Parameters:

  • image_stack (ImageStack) –

    Image stack.

  • sample_idx (int) –

    Sample index.

  • channels (sequence of int or None) –

    Channel indices; None for all.

  • coords (sequence of int) –

    Patch start coordinates.

  • patch_size (sequence of int) –

    Patch size per spatial dimension.

Returns:

  • NDArray

    Patch data.

lateral_context_patch_constr(multiscale_count, padding_mode)

Create a lateral context PatchConstructor for MicroSplit.

Parameters:

  • multiscale_count (int) –

    The number of multiscale inputs that will be created including the original image size.

  • padding_mode ((reflect, wrap), default: "reflect" ) –

    How lateral context inputs will be padded at the edge of the image. See numpy.pad for more information.

Returns:

  • PatchConstructor

    The patch constructor function. It will return patches with the dimensions (C, L, (Z), Y, X) where L will be equal to multiscale_count, C is the number of channels in the image, and (Z), Y, X are the patch size.