- Mastering OpenCV 4 with Python
- Alberto Fernández Villán
- 479字
- 2025-04-04 14:41:17
File extensions
Although the images we are going to manipulate in OpenCV can be seen as rectangular arrays of RGB triplets (in the case of RGB images), they are not necessarily created, stored, or transmitted in that format. In this sense, some file formats, such as GIF, PNG, bitmaps, or JPEG, use different forms of compression (lossless or lossy) to represent images more efficiently.
In this way, and for the sake of completeness, a brief introduction to these image files is given here, with a special focus on the file formats supported by OpenCV. The following file formats (with the associated file extensions) are supported by OpenCV:
- Windows bitmaps: *.bmp and *.dib
- JPEG files: *.jpeg, *.jpg, and *.jpe
- JPEG 2000 files: *.jp2
- Portable Network Graphics: *.png
- Portable image format: *.pbm, *.pgm, and *.ppm
- TIFF files: *.tiff and *.tif
The Bitmap image file (BMP) or device independent bitmap (DIB) file format is a raster image file format that's used to store bitmap digital images. The BMP file format can deal with 2D digital images in various color depths and, optionally, with data compression, alpha channels, or color profiles.
Joint Photographic Experts Group (JPEG) is a raster image file format that's used to store images that have been compressed to store a lot of information in a small file.
JPEG 2000 is an image compression standard and coding system that uses wavelet-based compression techniques offering a high level of scalability and accessibility. In this way, JPEG 2000 compresses images with fewer artefacts than a regular JPEG.
Portable Network Graphics (PNG) is a compressed raster graphics file format, which was introduced in 1994 as an improved replacement for Graphics Interchange Format (GIF).
The portable pixmap format (PPM), the portable bitmap format (PBM), and the portable graymap format (PGM) specify rules for exchanging graphics files. Several applications refer to these file formats collectively as the portable anymap format (PNM). These files are a convenient and simple method of saving image data. Additionally, they are easy to read. In this sense, the PPM, PBM, and PGM formats are all designed to be as simple as possible.
Tagged Image File Format (TIFF) is an adaptable file format for handling images and data within a single file.
The lossless and lossy types of compression algorithms are applied to the image, resulting in images that are smaller than the uncompressed image. On the one hand, in lossless compression algorithms, the resulting image is equivalent to the original, meaning that after reversing the compression process, the resulting image is equivalent (equal) to the original. On the other hand, in lossy compression algorithms, the resulting image is not equivalent to the original, meaning that some details in the image are lost. In this sense, in many lossy compression algorithms, the level of compression can be adjusted.