Skip to content

Random Patching

Source

Random patching utilities.

extract_patches_random(arr, patch_size, target=None, seed=None)

Generate patches from an array in a random manner.

The method calculates how many patches the image can be divided into and then extracts an equal number of random patches.

It returns a generator that yields the following:

  • patch: np.ndarray, dimension C(Z)YX.
  • target_patch: np.ndarray, dimension C(Z)YX, if the target is present, None otherwise.

Parameters:

  • arr (ndarray) –

    Input image array.

  • patch_size (tuple of int) –

    Patch sizes in each dimension.

  • target (Optional[ndarray], default: None ) –

    Target array, by default None.

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

    Random seed.

Yields:

  • Generator[ndarray, None, None]

    Generator of patches.