Skip to content

Random Patching

Source

Random patching strategies.

FixedRandomPatching

Deterministic random patching strategy for validation.

Parameters:

  • data_shapes (sequence of (sequence of int)) –

    Shapes of the underlying data (axes SC(Z)YX).

  • patch_size (sequence of int) –

    Patch size per spatial dimension (length 2 or 3).

  • seed (int or None, default: None ) –

    Seed for reproducibility.

Notes

The output of get_patch_spec is deterministic (same index gives same output). The number of patches per sample is based on sequential non-overlapping coverage.

n_patches property

The number of patches that this patching strategy will return.

It also determines the maximum index that can be given to get_patch_spec.

Returns:

  • int

    Number of patches.

__init__(data_shapes, patch_size, seed=None)

A patching strategy for sampling random patches.

Parameters:

  • data_shapes (sequence of (sequence of int)) –

    The shapes of the underlying data. Each element is the dimension of the axes SC(Z)YX.

  • patch_size (sequence of int) –

    The size of the patch. The sequence will have length 2 or 3, for 2D and 3D data respectively.

  • seed (int, default: None ) –

    An optional seed to ensure the reproducibility of the random patches.

get_patch_indices(data_idx)

Get the patch indices will return patches for a specific image_stack.

The image_stack corresponds to the given data_idx.

Parameters:

  • data_idx (int) –

    An index that corresponds to a given image_stack.

Returns:

  • sequence of int

    A sequence of patch indices, that when used to index the CAREamicsDataset will return a patch that comes from theimage_stackcorresponding to the givendata_idx`.

get_patch_spec(index)

Return the patch specs for a given index.

Parameters:

  • index (int) –

    A patch index.

Returns:

  • PatchSpecs

    A dictionary that specifies a single patch in a series of ImageStacks.

RandomPatching

Random patching strategy.

Parameters:

  • data_shapes (sequence of (sequence of int)) –

    Shapes of the underlying data (axes SC(Z)YX).

  • patch_size (sequence of int) –

    Patch size per spatial dimension (length 2 or 3).

  • seed (int or None, default: None ) –

    Seed for reproducibility of random patches.

Notes

The output of get_patch_spec will be random, i.e. if the same index is given twice the two outputs can be different. The strategy still ensures a known number of patches per sample per image stack via bins; the index determines "data_idx" and "sample_idx" in the returned PatchSpecs, while "coords" are random. The number of patches per sample is based on sequential non-overlapping coverage of the array.

n_patches property

The number of patches that this patching strategy will return.

It also determines the maximum index that can be given to get_patch_spec.

Returns:

  • int

    Number of patches.

__init__(data_shapes, patch_size, seed=None)

A patching strategy for sampling random patches.

Parameters:

  • data_shapes (sequence of (sequence of int)) –

    The shapes of the underlying data. Each element is the dimension of the axes SC(Z)YX.

  • patch_size (sequence of int) –

    The size of the patch. The sequence will have length 2 or 3, for 2D and 3D data respectively.

  • seed (int, default: None ) –

    An optional seed to ensure the reproducibility of the random patches.

get_patch_indices(data_idx)

Get the patch indices will return patches for a specific image_stack.

The image_stack corresponds to the given data_idx.

Parameters:

  • data_idx (int) –

    An index that corresponds to a given image_stack.

Returns:

  • sequence of int

    A sequence of patch indices, that when used to index the CAREamicsDataset will return a patch that comes from theimage_stackcorresponding to the givendata_idx`.

get_patch_spec(index)

Return the patch specs for a given index.

Parameters:

  • index (int) –

    A patch index.

Returns:

  • PatchSpecs

    A dictionary that specifies a single patch in a series of ImageStacks.