Last active
March 2, 2021 02:48
-
-
Save cbur24/edebd3e392d53b8e9e76640ebad9ec49 to your computer and use it in GitHub Desktop.
Improve the Sentinel-2 cloud mask using morpholigical operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import odc.algo | |
#Extract boolean mask | |
mask = odc.algo.enum_to_bool(ds.SCL, | |
categories=['cloud shadows', 'cloud medium probability', | |
'cloud high probability', 'thin cirrus']) | |
# Close mask to remove small holes in cloud, open mask to | |
# remove narrow false positive cloud, then dilate | |
mask = odc.algo.binary_closing(mask, 2) | |
mask_cleaned = odc.algo.mask_cleanup(mask, r=(2, 10)) | |
# Add new mask as nodata pixels | |
ds_clean = odc.algo.erase_bad(ds, mask_cleaned) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment