Skip to content

Commit

Permalink
Correction on DWImageClustering for Average processing
Browse files Browse the repository at this point in the history
  • Loading branch information
hybam-dev committed Nov 8, 2021
1 parent f87f4f6 commit f7d6f63
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion WaterDetect.ini
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ VEGETATION = no
NOT_VEGETATED = no
WATER = no
UNCLASSIFIED = no
CLOUD_MEDIUM_PROBABILITY = no
CLOUD_MEDIUM_PROBABILITY = yes
CLOUD_HIGH_PROBABILITY = yes
THIN_CIRRUS = yes
SNOW = no
6 changes: 3 additions & 3 deletions runWaterDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def process_ext_masks():
'processed and copied manually into each image folder.',
default='S2_S2COR', type=str)
parser.add_argument("-d", "--dilation", type=int, required=False, default=0,
help='Size of the dilation kernel to be applied to the final mask. Default value is 0 '
'(no dilation).')
help='Size of the dilation kernel to be applied to the final mask in pixels. '
'Default value is 0 (no dilation).')
parser.add_argument("-f", "--flags", help="Values to be masked. Each value should be preceded by the -f "
"(ex. -f 2 -f 3 -f 15",
"(ex. -f 2 -f 3 -f 15)",
required=True, type=int, action='append')

args = parser.parse_args()
Expand Down
10 changes: 10 additions & 0 deletions waterdetect/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ def bitwise_or(array, bit_values):
def bitwise_and(array, bit_values):
return np.bitwise_and(array, bit_values)

@staticmethod
def flatten(x):
result = []
for el in x:
if isinstance(el, list):
result.extend(DWutils.flatten(el))
else:
result.append(el)
return result

@staticmethod
def listify(lst, uniques=[]):
# pdb.set_trace()
Expand Down
13 changes: 9 additions & 4 deletions waterdetect/External_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def prepare_external_masks(imgs_dir: str, masks_dir: str, flags: list, img_type:

# loop through the images. For each image, we will look for the corresponding mask
for img in imgs:
mask = search_mask(img, masks_path, img_type)
if mask is not None:
print(f'Processing mask: {str(mask)}')
process_mask(mask, img, flags, dilation=dilation)
try:
mask = search_mask(img, masks_path, img_type)
if mask is not None:
print(f'Processing mask: {str(mask)}')
process_mask(mask, img, flags, dilation=dilation)

except Exception as e:
print(e)
print(f'Problem processing mask {mask.name}')
5 changes: 4 additions & 1 deletion waterdetect/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def get_necessary_bands(self):
Check the config file and all the parametrization to return a set of bands needed to run the algorithm
"""

# first we will flatten the bands_keys list (it can contain list of lists)
bands = DWutils.flatten(self.bands_keys)

# create a set from the bands_keys
bands = set(self.bands_keys)
bands = set(bands)

# include the reference band
bands.add(self.config.reference_band)
Expand Down

0 comments on commit f7d6f63

Please sign in to comment.