Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose invalid pixel buffering parameter #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

[0.1.5] (2022-11-11)
--------------------
Changed
*******
- enables setting the buffer size of invalid areas via `invalid_buffer` parameter

[0.1.4] (2022-03-03)
----------------------
Changed
Expand Down
2 changes: 1 addition & 1 deletion ukis_csmask/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.4"
__version__ = "0.1.5"
8 changes: 5 additions & 3 deletions ukis_csmask/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(
img,
band_order=None,
nodata_value=None,
invalid_buffer=4,
):
"""
:param img: Input satellite image of shape (rows, cols, bands). (ndarray).
Expand All @@ -24,6 +25,7 @@ def __init__(
:param band_order: Image band order. (dict).
>>> band_order = {0: "Blue", 1: "Green", 2: "Red", 3: "NIR", 4: "SWIR1", 5: "SWIR2"}
:param nodata_value: Additional nodata value that will be added to valid mask. (num).
:param invalid_buffer: Number of pixel that should be buffered around invalid areas.
"""
# consistency checks on input image
if band_order is None:
Expand Down Expand Up @@ -65,7 +67,7 @@ def __init__(
self.band_order = band_order
self.nodata_value = nodata_value
self.csm = self._csm()
self.valid = self._valid()
self.valid = self._valid(invalid_buffer)

def _csm(self):
"""Computes cloud and cloud shadow mask with following class ids: 0=background, 1=clouds, 2=cloud shadows.
Expand Down Expand Up @@ -100,7 +102,7 @@ def _csm(self):

return csm

def _valid(self):
def _valid(self, invalid_buffer):
"""Converts the cloud and cloud shadow mask into a binary valid mask with following class ids:
0=invalid (clouds, cloud shadows, nodata), 1=valid (rest). Invalid pixels are buffered to reduce effect of
cloud and cloud shadow fuzzy boundaries. If CSmask was initialized with nodata_value it will be added to the
Expand All @@ -115,7 +117,7 @@ def _valid(self):
# dilate the inverse of the binary valid pixel mask (invalid=0)
# this effectively buffers the invalid pixels
valid_i = ~valid.astype(np.bool)
valid = (~ndimage.binary_dilation(valid_i, iterations=4).astype(np.bool)).astype(np.uint8)
valid = (~ndimage.binary_dilation(valid_i, iterations=invalid_buffer).astype(np.bool)).astype(np.uint8)

if self.nodata_value is not None:
# add image nodata pixels to valid pixel mask
Expand Down