Python API¶
This section includes information for using the pure Python API of
bob.io.image.
- 
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 theextensionparameter, which can have the following values:None: The file name extension of thefilenameis used to determine the image type.'auto': The type of the image will be detected automatically, usingbob.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 - The image read from the specified file.
 
numpy.ndarrayof typeuint8
- 
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 theextensionparameter, which can have the following values:None: The file name extension of thefilenameis used to determine the image type.'auto': The type of the image will be detected automatically, usingbob.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 - The image read from the specified file.
 
numpy.ndarrayof typeuint8
- 
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 bybob.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., inbob.io.image.load().Parameters:
image_name: strThe name (including path) of the image to checkReturns:
extension: strThe 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. IfcmapisNoneandimg.ndimis 2, defaults to ‘gray’.cmapis ignored whenimghas RGB(A) information. - kwargs – These are passed directly to 
matplotlib.pyplot.imshow() 
- img (numpy.ndarray) – A 2 or 3 dimensional array containing an image in
bob style: For a 2D array (grayscale image) should be 
 
- 
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 
imgcompatible with matplotlib.pyplot.imshow().
Return type: numpy.ndarray - A view of the