Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load png images with 4 channels?

Tags:

opencv

I have been trying to load .png files with transparency channel (RGB and Alph) with no luck. It appears that openCV strips the 4th channel out of the image. Is there any method to load the image with the complete 4 channels including the alpha channel even if I had to modify the OpenCV source code and rebuild it?

like image 559
Mohammad Elwakeel Avatar asked Sep 27 '10 12:09

Mohammad Elwakeel


People also ask

Can a PNG have 4 channels?

PNG images usually have four channels. Three color channels for red, green and blue, and the fourth channel is for transparency, also called alpha channel.

How many channels does PNG image have?

The PNG file format supports images with two channels with a bit depth of 16 or 32 bits (per channel). PNG interprets such a file as a grayscale image with an alpha (i.e. transparency) channel.

What is a 4 channel image?

A CMYK image has four channels: cyan, magenta, yellow, and key (black). CMYK is the standard for print, where subtractive coloring is used. A 32-bit CMYK image (the industry standard as of 2005) is made of four 8-bit channels, one for cyan, one for magenta, one for yellow, and one for key color (typically is black).

What are channels in a PNG image?

The CMY and CMYK color systems, which are most often used in color printing, use three or four channels: Cyan, Magenta, Yellow, and Key (black). The HSL color system, which is the most modern color system and is often used in color picker tools, uses Hue, Saturation, and Lightness as channels.


1 Answers

If you are using OpenCV 2 or OpenCV 3 you should use IMREAD_* flags (as mentioned at here).

C++

using namespace cv; Mat image = imread("image.png", IMREAD_UNCHANGED); 

Python

import cv2 im = cv2.imread("image.png", cv2.IMREAD_UNCHANGED) 
like image 199
Satya Mallick Avatar answered Sep 19 '22 02:09

Satya Mallick