C++ API¶
The C++ API of bob.io.image allows users to read and write images in different file formats.
For all image tyres, there exist two functions for reading and writing image, a function to peek the color information (if applicable) and a C++ class that can be used for more detailed information about the image.
Generic functions¶
These functions read and write images based on the filename extension.
Currently, only uint8_t data type is supported (because this data type is supported by all of our codes).
For other data types, please use the specialized functions as described below.
-
bool
bob::io::image::is_color_image(const std::string &filename)¶ Returns
trueif the image with the given name is a color image, elsefalse. It might raise an exception if the extension is not supported.
-
blitz::Array<uint8_t, 2>
bob::io::image::read_gray_image(const std::string &filename)¶ Reads a gray image. It might raise an exception if the extension is not supported.
-
blitz::Array<uint8_t, 3>
bob::io::image::read_color_image(const std::string &filename)¶ Reads a color image. It might raise an exception if the extension is not supported.
-
void
bob::io::image::write_gray_image(const blitz::Array<uint8_t, 2> &image, const std::string &filename)¶ Writes the gray
image. If the file exists, it will be overwritten.
-
void
bob::io::image::write_color_image(const blitz::Array<uint8_t, 3> &image, const std::string &filename)¶ Writes the color
image. If the file exists, it will be overwritten.
BMP¶
-
blitz::Array<uint8_t, 3>
bob::io::image::read_bmp(const std::string &filename)¶ Reads a color BMP image of data type
uint8_t.
-
void
bob::io::image::write_bmp(const blitz::Array<uint8_t, 3> &image, const std::string &filename)¶ Writes the BMP color
image. If the file exists, it will be overwritten. Onlyuint8_tdata type is supported.
GIF¶
-
blitz::Array<uint8_t, 3>
bob::io::image::read_gif(const std::string &filename)¶ Reads a color GIF image of data type
uint8_t.
-
void
bob::io::image::write_gif(const blitz::Array<uint8_t, 3> &image, const std::string &filename)¶ Writes the GIF color
image. If the file exists, it will be overwritten. Onlyuint8_tdata type is supported.
JPEG¶
-
bool
bob::io::image::is_color_jpeg(const std::string &filename)¶ Returns
trueif the JPEG image with the given name is a color image, elsefalse.
-
template<int
N> -
blitz::Array<uint8_t, N>
bob::io::image::read_jpeg(const std::string &filename)¶ Reads a JPEG image of the given type (grayscale:
N=2or color:N=3). Onlyuint8_tdata type is supported. Please assure that you read images of the correct color type, seebob::io::image::is_color_jpeg().
-
template<int
N> -
void
bob::io::image::write_jpeg(const blitz::Array<uint8_t, N> &image, const std::string &filename)¶ Writes the JPEG
imageof the given type (grayscale:N=2or color:N=3) to a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tdata type is supported.
TIFF¶
-
bool
bob::io::image::is_color_tiff(const std::string &filename)¶ Returns
trueif the TIFF image with the given name is a color image, elsefalse.
-
template<class
T, intN> -
blitz::Array<T, N>
bob::io::image::read_tiff(const std::string &filename)¶ Reads a TIFF image of the given type (grayscale:
N=2or color:N=3). Onlyuint8_tanduint16_tdata types are supported. Please assure that you read images of the correct color type, seebob::io::image::is_color_tiff().
-
template<class
T, intN> -
void
bob::io::image::write_tiff(const blitz::Array<T, N> &image, const std::string &filename)¶ Writes the TIFF
imageof the given type (grayscale:N=2or color:N=3) to a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported.
PNG¶
-
bool
bob::io::image::is_color_png(const std::string &filename)¶ Returns
trueif the PNG image with the given name is a color image, elsefalse.
-
template<class
T, intN> -
blitz::Array<T, N>
bob::io::image::read_png(const std::string &filename)¶ Reads a PNG image of the given type (grayscale:
N=2or color:N=3). Onlyuint8_tanduint16_tdata types are supported. Please assure that you read images of the correct color type, seebob::io::image::is_color_png().
-
template<class
T, intN> -
void
bob::io::image::write_png(const blitz::Array<T, N> &image, const std::string &filename)¶ Writes the PNG
imageof the given type (grayscale:N=2or color:N=3) to a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported.
NetPBM¶
Note
Internally, the image IO is based on the filename extension to decide, which codec to use.
Hence, the filename extension needs to match the function and data type that you use.
Use .pbm for binary, .pgm for gray level images, and any other extension (typically .ppm) for color images.
-
bool
bob::io::image::is_color_p_m(const std::string &filename)¶ Returns
trueif the image with the given name is a color image, elsefalse.
-
template<class
T, intN> -
blitz::Array<T, N>
bob::io::image::read_p_m(const std::string &filename)¶ Reads an image of the given type (grayscale:
N=2or color:N=3). Onlyuint8_tanduint16_tdata types are supported. Please assure that you read images of the correct color type, seebob::io::image::is_color_p_m().
-
template<class
T, intN> -
void
bob::io::image::write_p_m(const blitz::Array<T, N> &image, const std::string &filename)¶ Writes the
imageof the given type (grayscale:N=2or color:N=3) to a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported.
-
template<class
T> -
blitz::Array<T, 2>
bob::io::image::read_pbm(const std::string &filename)¶ Reads an binary image. Only
uint8_tanduint16_tdata types are supported. Filename extension.pbmis required.
-
template<class
T> -
void
bob::io::image::write_pbm(const blitz::Array<T, 2> &image, const std::string &filename)¶ Writes the binary
imageto a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported. Filename extension.pbmis required.
-
template<class
T> -
blitz::Array<T, 2>
bob::io::image::read_pgm(const std::string &filename)¶ Reads an grayscale image. Only
uint8_anduint16_data types are supported. Filename extension.pgmis required.
-
template<class
T> -
void
bob::io::image::write_pgm(const blitz::Array<T, 2> &image, const std::string &filename)¶ Writes the grayscale
imageto a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported. Filename extension.pgmis required.
-
template<class
T> -
blitz::Array<T, 3>
bob::io::image::read_ppm(const std::string &filename)¶ Reads an binary color image. Only
uint8_anduint16_data types are supported. Filename extension cannot be.pbmor.pgm.
-
template<class
T> -
void
bob::io::image::write_ppm(const blitz::Array<T, 3> &image, const std::string &filename)¶ Writes the color
imageto a file with the givenfilename. If the file exists, it will be overwritten. Onlyuint8_tanduint16_tdata types are supported. Filename extension cannot be.pbmor.pgm.