Skip to content

Basic Patch Constructor

Source

Basic patch constructor implementation.

BasicPatchConstr

Bases: PatchConstr

Construct standard CAREamics input and optional target patches.

This constructor can be used for both training and prediction pipelines.

Parameters:

  • patching_strategy (Patching) –

    Strategy that maps dataset indices to patch specifications.

  • input_extractor (PatchExtractor) –

    Extractor for input patches.

  • target_extractor (PatchExtractor or None, default: None ) –

    Extractor for target patches. Can be None for self-supervised algorithms or prediction pipelines.

  • channels (Sequence[int] or None, default: None ) –

    Channel indices to extract. If None, all channels are extracted.

input_shapes property

Return input image shapes.

Returns:

n_patches property

Return the number of available patches.

Returns:

  • int

    Number of available patches.

target_shapes property

Return target image shapes, if targets exist.

Returns:

  • Sequence[Sequence[int]] or None

    Target image shapes in SC(Z)YX format, if targets exist, otherwise None.

__init__(patching_strategy, input_extractor, target_extractor=None, channels=None)

Initialize the basic patch constructor.

Parameters:

  • patching_strategy (Patching) –

    Strategy that maps dataset indices to patch specifications.

  • input_extractor (PatchExtractor) –

    Extractor for input patches.

  • target_extractor (PatchExtractor or None, default: None ) –

    Extractor for target patches. Can be None for self-supervised algorithms or prediction pipelines.

  • channels (Sequence[int] or None, default: None ) –

    Channel indices to extract. If None, all channels are extracted.

construct_patch(index)

Construct the input and optional target patch for an index.

Parameters:

  • index (int) –

    Dataset index to map to a patch specification.

Returns:

  • input_patch ( NDArray[Any] ) –

    Input patch with axes C(Z)YX.

  • target_patch ( NDArray[Any] or None ) –

    Target patch with axes C(Z)YX when a target extractor is available, otherwise None.

  • patch_spec ( PatchSpecs ) –

    Patch specification used to extract the patches.

get_input_image_metadata(patch_spec)

Return metadata for the input image described by a patch specification.

Parameters:

  • patch_spec (PatchSpecs) –

    Patch specification containing the input image index.

Returns:

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_principal_input(input_patch)

Return the principal input patch.

The principal input is used for calculating statistics for normalization.

Parameters:

  • input_patch (NDArray[Any]) –

    Input patch with axes C(Z)YX.

Returns:

  • NDArray[Any]

    The unchanged input patch with axes C(Z)YX.

get_target_image_metadata(patch_spec)

Return metadata for the target image described by a patch specification.

Parameters:

  • patch_spec (PatchSpecs) –

    Patch specification containing the target image index.

Returns:

  • ImageMetadata | None

    Metadata for the target image when targets exist, otherwise None.