Python API¶
This section includes information for using the pure Python API of
bob.io.image
.
- bob.io.image.bob_to_opencvbgr(img)[source]¶
Returns a view of the image from Bob format to OpenCV BGR format. This function works with images, batches of images, videos, and higher dimensional arrays that contain images.
- Parameters
img (numpy.ndarray) – An image loaded by Bob. It needs to have at least 3 dimensions.
- Returns
A view of the
img
compatible with OpenCV.- Return type
- Raises
ValueError – If the image dimension is less than 3.
- 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.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.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
(h, w)
; A 3D array (color image) should be in the(c, h, w)
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.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.opencvbgr_to_bob(img)[source]¶
Returns a view of the image from OpenCV BGR format to Bob RGB format. This function works with images, batches of images, videos, and higher dimensional arrays that contain images.
- Parameters
img (numpy.ndarray) – An image loaded by OpenCV. It needs to have at least 3 dimensions.
- Returns
A view of the
img
compatible with Bob.- Return type
- Raises
ValueError – If the image dimension is less than 3.
- 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.to_bob(img)[source]¶
Returns a view of the image from matplotlib format to Bob format. This function works with images, batches of images, videos, and higher dimensional arrays that contain images.
- Parameters
img (numpy.ndarray) – An image in matplotlib format (channels last): For an ND array (N >= 3), the image should have the following format:
(..., h, w, c)
.- Returns
A view of the
img
compatible with Bob.- Return type
- bob.io.image.to_matplotlib(img)¶
Returns a view of the image from Bob format to matplotlib format. This function works with images, batches of images, videos, and higher dimensional arrays that contain images.
- Parameters
img (numpy.ndarray) – A N dimensional array containing an image in Bob format (channels first): For an ND array (N >= 3), the image should have the following format:
(..., c, h, w)
.- Returns
A view of the
img
compatible withmatplotlib.pyplot.imshow()
.- Return type