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
- 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
- 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