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:

Name Type Description Default
arr ndarray

Input image array.

required
patch_size tuple of int

Patch sizes in each dimension.

required
target Optional[ndarray]

Target array, by default None.

None
seed int or None

Random seed.

None

Yields:

Type Description
Generator[ndarray, None, None]

Generator of patches.