Lydorn / Polygonization-by-Frame-Field-Learning

This repository contains the code for our fast polygonal building extraction from overhead images pipeline.
BSD 3-Clause "New" or "Revised" License
288 stars 70 forks source link

distance transform #13

Closed wangyi111 closed 3 years ago

wangyi111 commented 3 years ago

hi, may i ask how to calculate the distance to the second nearest building? i'm not quite familiar with that, i know with cv2.distanceTransform we can calculate distance to the nearest building.

Lydorn commented 3 years ago

@wangyi111 Hi, yes you can see in the code of the compute_raster_distances_sizes() function how it is done: https://github.com/Lydorn/pytorch_lydorn/blob/69d6b0a3ace94cdb3204708b00862b30391f727c/torch_lydorn/torchvision/transforms/rasterize.py#L52 It is a relatively expensive computation: it uses cv2.distanceTransform for each building in the ground truth at a time and then sorts distances for each pixel and adds the 2 smallest distances together.

wangyi111 commented 3 years ago

i see, that's quite complicated. how do you use this function in your experiment? Saying we have binary building mask as ground truth, how do you go to this function? (is there a preprocessing to get polygons?)

wangyi111 commented 3 years ago

also, did you try only one distance? how well did that perform?

Lydorn commented 3 years ago

@wangyi111 sorry for the very late reply, for frame field it is required to have ground truth polygons because the ground truth angle has to be computed. If you only have binary building mask as ground truth it is not straightforward as you need to first convert them to polygons. I had the same problem for the Inria Aerial Image Labeling Dataset which only has raster ground truth masks. You can use this script: https://github.com/Lydorn/Polygonization-by-Frame-Field-Learning/blob/master/polygonize_mask.py to polygonize your ground truth masks first.

I did not try only one distance. The idea of using the smallest two distances is to increase the loss between two objects very close together so that they can be seperated better.

wangyi111 commented 3 years ago

understand, Thank you!