MarcoForte / FBA_Matting

Official repository for the paper F, B, Alpha Matting
MIT License
464 stars 95 forks source link

Trimap Generation #35

Closed ritvikagrawal1 closed 3 years ago

ritvikagrawal1 commented 3 years ago

The paper does not mention the method to generate trimap from the given alpha matte. Can you please elaborate on how you have generated trimap from matte in the Alpha Composition 1k dataset. OR in case if matte is not given, how can we generate trimap?

kartikwar commented 3 years ago

you can use this code

def gen_trimap(alpha): k_size = random.choice(range(2, 5)) iterations = np.random.randint(5, 15) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (k_size, k_size)) dilated = cv2.dilate(alpha, kernel, iterations=iterations) eroded = cv2.erode(alpha, kernel, iterations=iterations) trimap = np.zeros(alpha.shape) trimap.fill(128)

trimap[alpha >= 255] = 255

trimap[eroded >= 255] = 255
trimap[dilated <= 0] = 0
return trimap

see the link https://github.com/huochaitiantang/pytorch-deep-image-matting/blob/master/core/data.py for more info