Skip to content

could we include 4-channels images, too? i.e. 4D alpha images? #15927

Closed

Description

if (mask.channels() == 3)

reason: all images with 4 channels (alpha channels) are required to be converted to 3 channels on the client side, then back to 3 channels just for API compatibility purposes.

Activity

  1. ghost changed the title [-]could this not include alpha 4-channel images, too?[/-] [+]could we include 4-channels images, too? i.e. 4D alpha images?[/+] on Nov 17, 2019
  2. nappaillav commented on Dec 30, 2019

    @nappaillav

    Hello
    I am new to opencv community and would like to work on this issue. So I just wanted to know if the following code would resolve the issue. If not, do let me know how to resolve the issue

    `

    static Mat checkMask(InputArray _mask, Size size)
    {
        Mat mask = _mask.getMat();
        Mat gray;
        
        if (mask.channels() == 3)
            cvtColor(mask, gray, COLOR_BGR2GRAY);
        
        else if(mask.channels() == 4)
            cvtColor(mask, gray, COLOR_BGRA2GRAY);
        
        else
        {
            if (mask.empty())
                gray = Mat(size.height, size.width, CV_8UC1, Scalar(255));
            else
                mask.copyTo(gray);
        }
        
        return gray;
    }
    

    `

  3. Lalit-garg commented on Jan 17, 2020

    @Lalit-garg

    Surely,we can use this to convert 3 channels to 4 channels
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGBA)
    And similarly we can convert into 3 channels .
    So, we use RGBA2BGR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions