Skip to content

cv::cvtColor does not properly take transparency into account #13135

Open
@PhilLab

Description

@PhilLab
System information (version)
  • OpenCV => 3.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2013
Detailed description

cv::cvtColor(image, outImage, cv::COLOR_BGRA2GRAY`); and cv::cvtColor(image, outImage, cv::COLOR_BGRA2BGR); don't handle transparency well: RGB pixel values determine the output even if alpha value is zero.

One could indeed argue that its because of a "wrong" image but this seems to be what many standard editing tools / conversion tools produce

Steps to reproduce

Use this test image at path: PngWithTransparency.png

cv::Mat image= cv::imread(path, cv::IMREAD_UNCHANGED);
cv::Mat noAlpha, noAlphaGray;
cv::cvtColor(image, noAlpha, cv::COLOR_BGRA2BGR);
cv::cvtColor(image, noAlphaGray, cv::COLOR_BGRA2GRAY);

This is what is inside the images, a black "bounding box" and then fully white border around. Expected would be a full black background.

image

BTW: cv::imshow("image", image) would produce the same result as noAlpha

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions