SatelliteShorelines / CoastSeg

An interactive toolbox for downloading satellite imagery, applying image segmentation models, mapping shoreline positions and more. The mapping extension for CoastSat and Zoo.
https://satelliteshorelines.github.io/CoastSeg/
GNU General Public License v3.0
48 stars 10 forks source link

Feature Request: Toggle for Cloud Masking #188

Closed 2320sharon closed 1 year ago

2320sharon commented 1 year ago

Feature Request: Toggle for Cloud Masking

Description: Introduce a toggle switch to enable or disable cloud masking. By default, this toggle would be set to "off". If users find that the Landsat's cloud masking algorithm erroneously labels beach pixels as cloud pixels, they can activate this switch to disable all cloud masking.

Proposed Solution:

  1. Add a toggle switch/button in the user interface, preferably in the settings or preferences section.
  2. Link the toggle's state (on/off) to the cloud masking function.
  3. When the toggle is "off", the cloud masking algorithm should be bypassed during image processing.

Benefits:

Drawbacks:

  1. Turning off cloud masking might expose actual cloud-covered areas, potentially affecting the accuracy of shoreline extraction in those regions.

Additional Context:

2320sharon commented 1 year ago

I've been researching how cloud masks are created and how they applied within coastsat_package.

What is the cloud mask?

The cloud mask is a binary mask that indicates where cloud pixels have been identified. The version of the cloud mask returned by preprocess_single is the cloud mask merged via a logical OR operation with the no_data mask.

Where is the cloud mask generated?

It is generated by the generate_cloud_mask function within preprocess_single.

Where is the cloud mask applied?

  1. rescale_image_intensity used by save_single_jpg
  2. create_shoreline_buffer
  3. classify_image_NN
  4. adjust_detection (we don't care becasue we set this to false)
  5. find_wl_contours1
  6. find_wl_contours2
  7. process_shoreline : uses only the cloud mask. Not the cloud mask with the no-data pixels in it
  8. show_detection
2320sharon commented 1 year ago

We found a way to save jpgs without the cloud mask thanks to @dbuscombe-usgs here is the basic concept that need to be applied to preprocess_single

do_cloud_mask = False 
cloud_mask = create_cloud_mask(im_QA, satname, cloud_mask_issue, collection)

if not do_cloud_mask:
    cloud_mask[:]=False
    cloud_mask = get_nodata_mask(im_ms, cloud_mask.shape)
    # add pixels with -inf or nan values on any band to the nodata mask
    im_nodata = get_nodata_mask(im_ms, cloud_mask.shape)
    # check if there are pixels with 0 intensity in the Green, NIR and SWIR bands and add those
    # to the cloud mask as otherwise they will cause errors when calculating the NDWI and MNDWI
    im_zeros = get_zero_pixels(im_ms, cloud_mask.shape)
    # add zeros to im nodata
    im_nodata = np.logical_or(im_zeros, im_nodata)
else:
    cloud_mask = get_nodata_mask(im_ms, cloud_mask.shape)
    # add pixels with -inf or nan values on any band to the nodata mask
    im_nodata = get_nodata_mask(im_ms, cloud_mask.shape)
    # check if there are pixels with 0 intensity in the Green, NIR and SWIR bands and add those
    # to the cloud mask as otherwise they will cause errors when calculating the NDWI and MNDWI
    im_zeros = get_zero_pixels(im_ms, cloud_mask.shape)
    # add zeros to im nodata
    im_nodata = np.logical_or(im_zeros, im_nodata)

    # update cloud mask with all the nodata pixels
    cloud_mask = np.logical_or(cloud_mask, im_nodata)
2320sharon commented 1 year ago

This feature has been added in coastsat-package 0.1.16. There is a toggle in the basic settings that can be set to False to turn off cloud masking. This works for both downloading imagery and for extracting shorelines pip install coastseg==0.0.75dev8