Updated by Kirill Kornyakov over 11 years ago
When decoding the transparent image in attachment (test image made with gimp) to a Mat, the alpha channel is stripped.
The image is coming from a resource on android and is decoded with
Mat m = Utils.loadResource(c,R.drawable.rgbt, Highgui.CV_LOAD_IMAGE_UNCHANGED);
==> m.channels = 3
After more analyse:
Utils.loadResource is calling imgdecode with -1 as flags
imgdecode is calling the png decoder in the grfmt_png.cpp file
In the PngDecoder::readHeader function, the image is detected as having a color_type of PNG_COLOR_TYPE_PALETTE
and then m_type = CV_8UC3
Remarks:
- If I modify the code so that m_type = CV_8UC4 in case of a PNG_COLOR_TYPE_PALETTE, the alpha channel is not stripped and the mat returned is correct
- using pnginfo on the image we have :
Image Width: 10 Image Length: 10
Bitdepth (Bits/Sample): 8
Channels (Samples/Pixel): 4
Pixel depth (Pixel Depth): 32
Colour Type (Photometric Interpretation): RGB with alpha channel
Image filter: Single row per byte filter
Interlacing: No interlacing
Compression Scheme: Deflate method 8, 32k window
Resolution: 2835, 2835 (pixels per meter)
FillOrder: msb-to-lsb
Byte Order: Network (Big Endian)
Number of text strings: 1 of 9
Comment (xTXt deflate compressed): Created with GIMP