mltk.core.preprocess.utils.image

Utilities for processing image data

Functions

read_image_file(path[, target_channels, ...])

Reads and decodes an image file.

write_image_file(path, sample[, auto_scale, ...])

Write image data to a file

read_image_file(path, target_channels=0, return_numpy=False)[source]

Reads and decodes an image file.

Parameters:
  • path (Union[str, ndarray, Tensor]) – Path to image file as a python string, numpy string, or tensorflow string

  • target_channels – Number of channels to return image as, if 0 then use native channels

  • return_numpy – If true then return numpy array, else return TF tensor

Return type:

Union[ndarray, Tensor]

Returns:

Image data as numpy array or TF tensor

write_image_file(path, sample, auto_scale=True, batch_size=None)[source]

Write image data to a file

Parameters:
  • path (str) – File path to save image If this is does NOT end with .jpg, then the path is assumed to be a directory. In this case, the image path is generated as: <path>/<timestamp>.jpg

  • sample (Union[ndarray, Tensor]) – Image data to write, if the data type is: - int8 then it is converted to uint8 - float32 and auto_scale=True then the image is automatically scaled to 0-255

  • auto_scale – Automatically scale the image data to 0-255 if it is float32

  • batch_size (int) – This allows for using this function within a tf.keras.layers.Lambda layer If used, this will write each image in the given batch

Return type:

Union[str, Tensor]

Returns:

Path to written file. If this is executing in a non-eager TF function then the path is a TF Tensor, otherwise it is a Python string