module documentation

Image patch utilities.

Copyright 2017-2025, Voxel51, Inc.

Class ImagePatchesExtractor Class for iterating over the labeled/unlabeled image patches in a collection.
Function extract_patch Extracts the patch from the image.
Function parse_patches Parses the patches from the given document.
Function _load_image Undocumented
Function _to_classification Undocumented
def extract_patch(img, detection, force_square=False, alpha=None): (source)

Extracts the patch from the image.

Parameters
imga numpy image array
detectiona fiftyone.core.labels.Detection defining the patch
force_square:Falsewhether to minimally manipulate the patch bounding box into a square prior to extraction
alpha:Nonean optional expansion/contraction to apply to the patch before extracting it, in [-1, inf). If provided, the length and width of the box are expanded (or contracted, when alpha < 0) by (100 * alpha)%. For example, set alpha = 0.1 to expand the box by 10%, and set alpha = -0.1 to contract the box by 10%
Returns
the image patch
def parse_patches(doc, patches_field, handle_missing='skip'): (source)

Parses the patches from the given document.

Parameters
docUndocumented
patches_fieldthe name of the field defining the image patches. Must be of type fiftyone.core.labels.Detection, fiftyone.core.labels.Detections, fiftyone.core.labels.Polyline, or fiftyone.core.labels.Polylines
handle_missing:"skip"

how to handle documents with no patches. Supported values are:

  • "skip": skip the document and return None
  • "image": use the whole image as a single patch
  • "error": raise an error
Returns
a fiftyone.core.labels.Detections instance, or None
def _load_image(image_path, force_rgb=False): (source)

Undocumented

def _to_classification(label): (source)

Undocumented