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 theextension
parameter, which can have the following values:None
: The file name extension of thefilename
is 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
strThe 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 3Dnumpy.ndarray
of typeuint8
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 theextension
parameter, which can have the following values:None
: The file name extension of thefilename
is 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
strThe 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 3Dnumpy.ndarray
of typeuint8
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 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 check
Returns:
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)
; A 3D array (color image) should be in the(n, y, x)
format.cmap (matplotlib.colors.Colormap) – Colormap, optional, default:
None
. Ifcmap
isNone
andimg.ndim
is 2, defaults to ‘gray’.cmap
is ignored whenimg
has RGB(A) information.**kwargs – These are passed directly to
matplotlib.pyplot.imshow()
- Returns
Returns whatever
plt.imshow
returns.- Return type
-
bob.io.image.
to_bob
(img)[source]¶ Returns a view of the image compatible with Bob.
- Parameters
img (numpy.ndarray) – A 2 or 3 dimensional array containing an image in matplotlib style: For a 2D array (grayscale image) should be
(y, x)
; For a 3D array (color image) should be(y, x, n)
.- Returns
A view of the
img
compatible with Bob(n, y, x)
for 3D images.- Return type
-
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 withmatplotlib.pyplot.imshow()
.- Return type