Discussions>How to get a matting trimap?>

How to get a matting trimap?

I'm trying to use a matting model, but most of them require the trimap as an input.
How to avoid it? or is there a way to get trimap from images?

2 votesJW270.00
1 Answers

First, you need to decide which model fits better with your needs. There are matting models, which don't require trimap during inference, but if you have to choose a model, which requires trimap at the input, you can do the following.

  • If you don't have segmented masks as well, run another segmentation model and get segmentation the masks (of course you gonna have quality drops)
  • After It, you can get trimap by using the binary maps

There are different ways to get trimap from the binary mask. Here are a couple of them

  1. Use 2D dilation (sometimes randomly) and defined 3 different areas.
    B - the whole image, without the binary mask after dilation
    F - the part which was the foreground, before dilation
    U - which is the part between background and foreground, after dilation
    B, F, and U are the 3 different classes of trimap

  2. Or if you have a mask, which is not a binary mask (for example output of any network), you can define 3 areas the following way
    B - where values are exactly 0
    F - where values are exactly 1
    U - where values are from (0, 1)

You are going to have something like this

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?