Python API

This section includes information for using the pure Python API of bob.io.image.

bob.io.image.get_config()[source]

Returns a string containing the configuration information.

bob.io.image.load(filename, extension) → image[source]

This function loads and image from the file with the specified filename. The type of the image will be determined based on the extension parameter, which can have the following values:

  • None: The file name extension of the filename is used to determine the image type.
  • 'auto': The type of the image will be detected automatically, using bob.io.image.get_correct_image_extension().
  • '.xxx': The image type is determined by the given extension.
    For a list of possible extensions, see bob.io.base.extensions() (only the image extensions are valid here).

Parameters:

filename
: str
The name of the image file to load.
extension
: str
[Default: None] If given, the given extension will determine the type of the image. Use 'auto' to automatically determine the extension (this might take slightly more time).

Returns

image
: 2D or 3D numpy.ndarray of type uint8
The image read from the specified file.
bob.io.image.read(filename, extension=None)

load(filename, extension) -> image

This function loads and image from the file with the specified filename. The type of the image will be determined based on the extension parameter, which can have the following values:

  • None: The file name extension of the filename is used to determine the image type.
  • 'auto': The type of the image will be detected automatically, using bob.io.image.get_correct_image_extension().
  • '.xxx': The image type is determined by the given extension.
    For a list of possible extensions, see bob.io.base.extensions() (only the image extensions are valid here).

Parameters:

filename
: str
The name of the image file to load.
extension
: str
[Default: None] If given, the given extension will determine the type of the image. Use 'auto' to automatically determine the extension (this might take slightly more time).

Returns

image
: 2D or 3D numpy.ndarray of type uint8
The image read from the specified file.
bob.io.image.get_include_directories() → includes[source]

Returns a list of include directories for dependent libraries, such as libjpeg, libtiff, ... This function is automatically used by bob.extension.get_bob_libraries() to retrieve the non-standard include directories that are required to use the C bindings of this library in dependent classes. You shouldn’t normally need to call this function by hand.

Returns:

includes
: [str]
The list of non-standard include directories required to use the C bindings of this class. For now, only the directory for the HDF5 headers are returned.
bob.io.image.get_macros() → macros[source]

Returns a list of preprocessor macros, such as (HAVE_LIBJPEG, 1). This function is automatically used by bob.extension.get_bob_libraries() to retrieve the prerpocessor definitions that are required to use the C bindings of this library in dependent classes. You shouldn’t normally need to call this function by hand.

Returns:

macros
: [str]
The list of preprocessor macros required to use the C bindings of this class.
bob.io.image.get_correct_image_extension(image_name) → extension

Estimates the image type and return a corresponding extension based on file content

This function loads the first bytes of the given image, and matches it with known magic numbers of image files. If a match is found, it returns the corresponding image extension (including the leading '.' that can be used, e.g., in bob.io.image.load().

Parameters:

image_name : str

The name (including path) of the image to check

Returns:

extension : str

The extension of the image based on the file content
bob.io.image.imshow(img, cmap=None, **kwargs)

Plots the images that are returned by bob.io.base.load()

Parameters:
  • img (numpy.ndarray) – A 2 or 3 dimensional array containing an image in bob style: For a 2D array (grayscale image) should be (y, x); For a 3D array (color image) should be (n, y, x).
  • cmap (matplotlib.colors.Colormap) – Colormap, optional, default: None. If cmap is None and img.ndim is 2, defaults to ‘gray’. cmap is ignored when img has RGB(A) information.
  • kwargs – These are passed directly to matplotlib.pyplot.imshow()
bob.io.image.to_matplotlib(img)

Returns a view of the image compatible with matplotlib.

Parameters:img (numpy.ndarray) – A 2 or 3 dimensional array containing an image in bob style: For a 2D array (grayscale image) should be (y, x); For a 3D array (color image) should be (n, y, x).
Returns:
A view of the img compatible with
matplotlib.pyplot.imshow().
Return type:numpy.ndarray