- OpenCV - GUI
- OpenCV - Writing an Image
- OpenCV - Reading Images
- OpenCV - Storing Images
- OpenCV - Environment
- OpenCV - Overview
- OpenCV - Home
Types of Images
Image Conversion
Drawing Functions
- OpenCV - Adding Text
- OpenCV - Drawing Arrowed Lines
- OpenCV - Drawing Convex Polylines
- OpenCV - Drawing Polylines
- OpenCV - Drawing an Ellipse
- OpenCV - Drawing a Rectangle
- OpenCV - Drawing a Line
- OpenCV - Drawing a Circle
Blur
Filtering
- OpenCV - Image Pyramids
- OpenCV - Morphological Operations
- OpenCV - Erosion
- OpenCV - Dilation
- OpenCV - Filter2D
- OpenCV - SQRBox Filter
- OpenCV - Box Filter
- OpenCV - Bilateral Filter
Thresholding
Sobel Derivatives
Transformation Operations
Camera and Face Detection
Geometric Transformations
Miscellaneous Chapters
OpenCV Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
OpenCV - The IMREAD_XXX Flag
OpenCV supports various types of images such as colored, binary, grayscale, etc. Using the imread() method and predefined fields of the Imgcodecs class, you can read a given image as another type.
The flags parameter of imread() method (IMREAD_XXX)
In the earper chapters, we have seen the syntax of imread() method of the Imgcodecs class. It accepts a string argument representing the location of the image that is to be read.
imread(filename)
The imread() method has another syntax.
imread(filename, int flags)
This syntax accepts two parameters −
filename − It accepts an argument (filename), a variable of the String type representing the path of the file that is to be read.
flags − An integer value representing a predefined flag value. For each value, this reads the given image as a specific type (gray scale color etc.)
Following is the table psting various fields provided in the Imgproc class as values for this parameter.
S.No | Fields and Description |
---|---|
1 |
IMREAD_COLOR If the flag is set to this value, the loaded image will be converted to a 3-channel BGR (Blue Green Red) color image. |
2 |
IMREAD_GRAYSCALE If the flag is set to this value, the loaded image will be converted to a single-channel grayscale image. |
3 |
IMREAD_LOAD_GDAL If the flag is set to this value, you can load the image using the gdal driver. |
4 |
IMREAD_ANYCOLOR If the flag is set to this value, the image is read in any possible color format. |
5 |
IMREAD_REDUCED_COLOR_2 IMREAD_REDUCED_COLOR_4 IMREAD_REDUCED_COLOR_8 If the flag is set to this value, the image is read as three-channel BGR, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used. |
6 |
IMREAD_REDUCED_GRAYSCALE_2 IMREAD_REDUCED_GRAYSCALE_4 IMREAD_REDUCED_GRAYSCALE_8 If the flag is set to this value, the image is read as a single-channel grayscale image, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used. |
7 |
IMREAD_UNCHANGED If the flag is set to this value, the loaded image is returned as it is. |