Ask Your Question

Revision history [back]

Grabcut output is the mask, not a complete segmented multichannel image.

What you need to do is convert the output mask into the alpha channel of your image; for this, best use "Split" on the input RGBA to separate the channels, discard the input A channel, and "Merge" back into the output RGBA the RGB channels from the input with the mask from Grabcut.

Or, if you want the mask applied to your input image, "Split" the channels like before, then Multiply each input RGB channel with the mask, and "Merge" then back like before.

As a side note, openCV GrabCut implementation for square foreground seeds works best if the rectangle is larger than the object to segment. Otherwise you might see an empty output mask...