open-forest-observatory / tree-detection-framework

BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Add mask-to-shapely function and example #37

Closed russelldj closed 3 weeks ago

russelldj commented 3 weeks ago

This adds a function to convert a binary mask to a shapely multipolygon and closes #30. It's inspired by @amrithasp02 's initial work using matplotlib and directly calls ContourPy, the library used by matplotlib. In the future we could explore other library implementations, but for now this seems relatively optimized and convenient. The function largely follows an example here.

I also added an example of using this function to visualize the boundaries of the predictions over the images. While it is not included in the tiles that are shown, I confirmed that this approach correctly handles both holes and multiple disconnected regions from the same mask. In both cases, all the information is represented in one shapely.MultiPolygon. As discussed, we could later post-process this to do things such as retaining the largest single component or filling holes.