# fiftyone.utils.image¶

Image utilities.

Functions:

 reencode_image(input_path, output_path) Re-encodes the image to the format specified by the given output path. reencode_images(sample_collection[, ext, …]) Re-encodes the images in the sample collection to the given format. transform_image(input_path, output_path[, …]) Transforms the image according to the provided parameters. transform_images(sample_collection[, size, …]) Transforms the images in the sample collection according to the provided parameters.
fiftyone.utils.image.reencode_images(sample_collection, ext='.png', force_reencode=True, delete_originals=False, num_workers=None, skip_failures=False)

Re-encodes the images in the sample collection to the given format.

The filepath of the samples are updated to point to the re-encoded images.

Parameters
• sample_collection – a fiftyone.core.collections.SampleCollection

• ext (".png") – the image format to use (e.g., “.png” or “.jpg”)

• force_reencode (True) – whether to re-encode images whose extension already matches ext

• delete_originals (False) – whether to delete the original images after re-encoding

• num_workers (None) – the number of worker processes to use. By default, multiprocessing.cpu_count() is used

• skip_failures (False) – whether to gracefully continue without raising an error if an image cannot be re-encoded

fiftyone.utils.image.transform_images(sample_collection, size=None, min_size=None, max_size=None, ext=None, force_reencode=False, delete_originals=False, num_workers=None, skip_failures=False)

Transforms the images in the sample collection according to the provided parameters.

The filepath of the samples are updated to point to the transformed images.

Note

This method will not update the metadata field of the collection after transforming. You can repopulate the metadata field if needed by calling:

sample_collection.compute_metadata(overwrite=True)

Parameters
• sample_collection – a fiftyone.core.collections.SampleCollection

• size (None) – an optional (width, height) for each image. One dimension can be -1, in which case the aspect ratio is preserved

• min_size (None) – an optional minimum (width, height) for each image. A dimension can be -1 if no constraint should be applied. The images are resized (aspect-preserving) if necessary to meet this constraint

• max_size (None) – an optional maximum (width, height) for each image. A dimension can be -1 if no constraint should be applied. The images are resized (aspect-preserving) if necessary to meet this constraint

• ext (None) – an optional image format to re-encode the source images into (e.g., “.png” or “.jpg”)

• force_reencode (False) – whether to re-encode images whose parameters already match the specified values

• delete_originals (False) – whether to delete the original images if any transformation was applied

• num_workers (None) – the number of worker processes to use. By default, multiprocessing.cpu_count() is used

• skip_failures (False) – whether to gracefully continue without raising an error if an image cannot be transformed

fiftyone.utils.image.reencode_image(input_path, output_path)

Re-encodes the image to the format specified by the given output path.

Parameters
• input_path – the path to the input image

• output_path – the path to write the output image

fiftyone.utils.image.transform_image(input_path, output_path, size=None, min_size=None, max_size=None)

Transforms the image according to the provided parameters.

Parameters
• input_path – the path to the input image

• output_path – the path to write the output image

• size (None) – an optional (width, height) for the image. One dimension can be -1, in which case the aspect ratio is preserved

• min_size (None) – an optional minimum (width, height) for the image. A dimension can be -1 if no constraint should be applied. The image is resized (aspect-preserving) if necessary to meet this constraint

• max_size (None) – an optional maximum (width, height)` for the image. A dimension can be -1 if no constraint should be applied. The image is resized (aspect-preserving) if necessary to meet this constraint