Charch-630 / FGI-Matting

The official repository for Deep Image Matting with Flexible Guidance Input
GNU General Public License v3.0
58 stars 12 forks source link

Question about threshold of 50 pixels #3

Open WANGEOGEO opened 3 years ago

WANGEOGEO commented 3 years ago

Hi,

Awesome work for introducing different forms of trimaps into training! After reading through the code implementation, there is one point I'm not sure about. In 3.1.2 'Simulating User Scribbles', it says 'To avoid the points being too close to each other, we set a threshold of 50 pixels between each two points'. After going through code in dataloader/Test_dataset/data_generator.py, class Genclickmap, seems there is no strict constraint applied on the distances between randomly selected fg points and bg points. I am not sure if I have missed some stuff, hope someone could help me. Thanks in advance.

Charch-630 commented 3 years ago

Thank you for your question,

In our implementation, there is constraint applied on the distance between each two FG points or BG points. But there is no distance constraint between FG points and BG points. This is a little bit different from what we mentioned in our paper.

In class Genclickmap, we get all the coordinates of FG and BG points. self.r_extend controls the distance between each two points which is the threshold of 50 pixels mentioned in the paper. To sample FG points, we first get a copy of the Trimap in Line 546(trimap_fg_sample = copy.deepcopy(trimap)) . Second, we use np.where to find out the FG area in Trimap, then we generate a random number through np.random.randint to sample a point in FG area. Last, we add this point to fg_points and fill the circle of radius self.r_extend centered at the sampled point on Trimap with a value of 128. And we do the same to get BG points. Since we use two copies of Trimap to generate FG points and BG points respectively, there is actually no distance limit between FG points and BG points.

I hope this can answer your question.

WANGEOGEO commented 3 years ago

Thanks for your quick reply.

Ah I am pretty sure that there is no distance constraint between FG points and BG points, but I am unsure about the use of self.r_extend. I found that this value is only used to draw the circles on trimap, but there is no constraint applied on random points sampling. To my understanding, the process is just randomly choosing points on FG/BG area, and draw a circle with radius 50 pixels.

Plz correct me if my understanding is wrong.

Charch-630 commented 2 years ago

Please note that our points are sampled one by one.

We first get a copy of the trimap, and then we use np.where(trimap_fg_sample==255) (Line 549) to find the set of all foreground points in the trimap copy. And we pick one of the points as the first sampled point. After that, we draw a solid circle with this point as center and self.r_extend as the radius on the trimap copy, and the value inside the circle become 128(Line 555). In this way, when we sample the next point, we can only choose points that are more than self.r_extend away from the last point in the trimap copy because we only select those in FG area(trimap value ==255).

That's why we use self.r_extend to draw circles and this is also why we first get a copy of the trimap(because we are goint to draw circles on it).

I hope this can answer your question.

WANGEOGEO commented 2 years ago

Ah I see. This is a fabulous approach! Thanks for answering my question :-)