AMA-Labs / cal-notebooks

CEOS Analytics Laboratory notebooks and tools
0 stars 1 forks source link

Investigate odc.algo.mask_cleanup() #19

Open JonDHo opened 6 months ago

JonDHo commented 6 months ago

I have recently come across the odc.algo.mask_cleanup() function. This seems quite useful to help remove some of the rough edges of cloud masking. This also helps to remove tiny areas of "cloud" which might actually just be highly reflective surfaces on buildings, etc. I think we should include this in our cloud masking examples to help provide users with an extra option for improving cloud masking.

There is a discussion of this at https://docs.dea.ga.gov.au/notebooks/How_to_guides/Using_load_ard/ (because it is part of the DEA load_ard() function), which includes the following image as a demonstration. image

See also https://docs.digitalearthafrica.org/en/latest/sandbox/notebooks/Frequently_used_code/Cloud_and_pixel_quality_masking.html#Applying-morphological-processing-on-the-cloud-mask

You can choose how aggressively to apply this feature and in recent work I have been using something like:

filters = [("opening", 2), ("dilation", 2)]
cloud_free_mask = mask_cleanup(cloud_free_mask, mask_filters=filters)

The opening and closing filters define how many pixels to expand and contract the mask by to filter out issues. Other examples demonstrate using 5 pixels, but I went with something more conservative.

See https://github.com/opendatacube/odc-algo/blob/325c25b1c444c7d2ef8c0da8887dbbc784afed77/odc/algo/_masking.py#L428 for details on the actual function and additional options:

closing  = remove small holes in cloud - morphological closing
opening  = shrinks away small areas of the mask
dilation = adds padding to the mask
erosion  = shrinks bright regions and enlarges dark regions

I haven't tested out all options yet.