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?
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.
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.
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).
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With