Karel911 / TRACER

TRACER: Extreme Attention Guided Salient Object Tracing Network (AAAI 2022) implementation in PyTorch
Apache License 2.0
195 stars 41 forks source link

Changing black background to transparent #21

Closed aycaecemgul closed 2 years ago

aycaecemgul commented 2 years ago

Hello, thanks for the code and paper. Amazing work! I was doing some tests and the model works very great. I wanted to see the results when background is transparent but i realized there is a black hue near edges when i applied the code below to change the background. I know that your project is RGB based but i wonder is there a workaround for me to get the results without black background or is it impossible? Thanks in advance.

img is the result of the model. color = (0, 0, 0) mask = np.where((img == color).all(axis=2), 0, 255).astype(np.uint8) result = img.copy() result = cv2.cvtColor(result, cv2.COLOR_BGR2BGRA) result[:, :, 3] = mask

model result: cat code result: result original image: cat

wooseok-shin commented 2 years ago

Hi, Thank you for your interest in our research.

we have updated inference.py to reflect your suggestion.

Using the updated code, we confirmed that some of the black lines disappeared as follows: image

This post-processing method has one hyper-parameter (threshold). We haven't tested it on many images, but the threshold between 200 and 250 probably works.