fieldsoftheworld / ftw-baselines

Code for running baseline models/experiments with the Fields of The World dataset
https://fieldsofthe.world/
MIT License
55 stars 4 forks source link

Filter out holes with threshold in polygonize command #39

Closed cholmes closed 3 weeks ago

cholmes commented 3 weeks ago

I agree it would be nice to find a way to fill the holes - though sometimes there are real holes in a field, it would be nice to have the option (just like the area filtering).

Originally posted by @hannah-rae in https://github.com/fieldsoftheworld/ftw-baselines/issues/31#issuecomment-2438518723

cholmes commented 3 weeks ago

@calebrob6 also mentioned shapely.geometry.Polygon(geom.exterior), but that would remove all holes, so would be good to see if there's a way we can just remove holes below a certain (user configured w/ default) size.

m-mohr commented 3 weeks ago

51 optionally filters out all holes.

How useful is it really to remove holes of s specific size though? It could be anything from a small bollard to a big house, all would be valid holes. Not sure you can really judge whether a hole is valid or not from the size.

So I'm not sure whether there are reasonable usecases outside "all" or "no" holes. Thoughts @cholmes ?

cholmes commented 3 weeks ago

I see this as just the flip side to 'simplify'. Simplify lets you remove shapes that are under X size, and defaults to about 5 pixels. And I think it's helpful even at 1 pixel - makes the output much smaller, and makes it so there's not all these little polygons that are clearly just a pixel big in the source imagery. I don't think the algorithm is really picking up a small bollard from a single pixel at this point. So I see this as more to filter out things below the threshold that you can really detect. For now 500 meters / 5 pixels seems like a good default, but then the command lets users control that if they want. If we built it off a 10 centimeter imagery product then 500 meters would be way too big, but you still may want to filter out little holes that are like 2 meters (2 pixels).

We could just have 'simplify' both remove holes and polygons at the same size. Or we could have them be two separate commands. But yeah, I really see this as a way to filter out 'noise' where the raster isn't really resolving stuff.