ViTMatte icon indicating copy to clipboard operation
ViTMatte copied to clipboard

How to Generated Trimap for an input image ?

Open minkvirparia opened this issue 2 years ago • 8 comments

I want to get an trimap of the input image, so that I can get foreground image using this two things (input image & corresponding trimap). Actually I want to build an PoC (Proof of Concept) which takes any image and generates its foreground image.

minkvirparia avatar Aug 18 '23 17:08 minkvirparia

Maybe you could refer to this issue.

JingfengYao avatar Aug 22 '23 04:08 JingfengYao

@minkvirparia Did you solve the problem? I have the same question - how's possible to generate trimap programmatically and not manually?

LukaGiorgadze avatar Dec 30 '23 18:12 LukaGiorgadze

If you mean generate from alpha mattes for training or generate from a segmentation map like MatAny, it is possible. However, if you mean automatic object detection, I'm afraid not.

For this purpose, you may refer to the keywords 'human matting'. Here is some great work: RVM(human video matting), SIM(semantic image matting), MODNet(realtime human matting).

JingfengYao avatar Jan 02 '24 02:01 JingfengYao

If you mean generate from alpha mattes for training or generate from a segmentation map like MatAny, it is possible. However, if you mean automatic object detection, I'm afraid not.

For this purpose, you may refer to the keywords 'human matting'. Here is some great work: RVM(human video matting), SIM(semantic image matting), MODNet(realtime human matting).

Yes, I mean generate from alpha mattes/maps. I have tools that generate this stuff, but VitMatte requires trimap, so how can I generate trimap from this kind of map?

tmpl5bdony3

LukaGiorgadze avatar Jan 02 '24 07:01 LukaGiorgadze

@LukaGiorgadze In ViTMatte, we generate in this way: https://github.com/hustvl/ViTMatte/blob/c2605975063bacd49852b9709cc1e0ebe58e4972/data/dim_dataset.py#L509

JingfengYao avatar Jan 02 '24 07:01 JingfengYao

@LukaGiorgadze In ViTMatte, we generate in this way:

https://github.com/hustvl/ViTMatte/blob/c2605975063bacd49852b9709cc1e0ebe58e4972/data/dim_dataset.py#L509

Thank you @JingfengYao! This is helpful!

I love your work, it's absolutely amazing!

btw I suggest you add a sponsor button so people can sponsor with some bucks 💸

LukaGiorgadze avatar Jan 02 '24 07:01 LukaGiorgadze

@LukaGiorgadze Thanks 😄

JingfengYao avatar Jan 02 '24 08:01 JingfengYao

import cv2

def trimap_process(mask,trimap_threshold=20): #cv2 edges = cv2.Canny(mask, 100, 200) kernel = np.ones((trimap_threshold, trimap_threshold), np.uint8) expanded_edges = cv2.dilate(edges, kernel, iterations=1) expanded_mask = mask.copy() expanded_mask[expanded_edges > 0] = 128 # Assign gray color to the expanded region # cv2.imwrite("expanded_mask.png",expanded_mask) return expanded_mask # trimap_mask

vijeshkpaei avatar Apr 03 '25 06:04 vijeshkpaei