OpenCV: imread() Method “IMREAD_UNCHANGED” Flag Is Explained

robototem
3 min readDec 29, 2021

Basically speaking, IMREAD_UNCHANGED flag or imread mode allows us to read transparent images. When we read images with OpenCV by using Python, we use “imread” method.

cv2.imread(“filename”, flags=)

It requires us to input two arguments.

The first argument is “filename” as string.

The filename can be written in two ways.

  1. The exact file location, name and format of the image.

cv2.imread(“C:/Users/cagat/Desktop/image.png”, flags=)

Here is some important notes to avoid errors.

  • Write whole string in quotation mark: “ ”
  • Use “/” while writing the location. Location information can be found under the properties of the picture.
  • Write image name correctly with its extension or format
  • Do not change the image location after coding

2. Just image name and format but with one condition.

cv2.imread(“image.png”, flags=)

You can also declare image location just with its name and format BUT the project file (.py file) and image must be in the same folder!

I suggest you to use this method which gives a clean coding and more organized file structure for you.

Let’s continue with the second argument: Flags=

Flags are like options. You choose how image should be read from the source. For this method flags are called as ImreadModes or imread flags. We have 13 different modes to set the type of flags. These methods can be found in the documentation of OpenCV at docs.opencv.org

docs.opencv.org

In this story, I will just focus on IMREAD_UNCHANGED flag which is described as below in the documentation.

docs.opencv.org

Let’s focus on the term “with alpha channel”..

You can think the image as the complied color values in an array. An image has 3 color channels: Red, Green and Blue Channel and the forth one is Alpha Channel.

IMREAD_UNCHANGED allows us to read the Alpha Channel of an image.

Alpha channel describes the transparency of the image. Transparency can be described as it is or with the term “Opacity” or “Alpha Value”. Let me visualize it for you.

So I assume that I clarified the Alpha Channel part.

docs.opencv.org

Let’s continue with the term “Ignore EXIF information

EXIF is the abbreviation of Exchangeable Image File Format which stores numerous information in its metadata at the moment that we shoot. These information may include values as it shown below.

exifdata.com

The important EXIF information for us when we read an image with IMREAD_UNCHANGED flag is “orientation” of an image. EXIF orientation information stores the positioning of the camera with respect to the ground. This allows us to take pictures disregarding the orientation of the camera.

So basically EXIF orientation is ignored with IMREAD_UNCHANGED flag.

One line of code stores many stories inside. This is all from me for now..

--

--

robototem

TIA Portal, Image Processing, Engineering, and my favorite topics