From 24e388ea5b9cc388133aa3ba5b571b776d2eec8c Mon Sep 17 00:00:00 2001 From: Yannick TANGUY Date: Wed, 25 Feb 2026 13:54:32 +0000 Subject: [PATCH 1/2] Fix regularization of vegetation : invert two steps and replace 0 by undefined_veg --- slurp/masks/vegetationmask.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/slurp/masks/vegetationmask.py b/slurp/masks/vegetationmask.py index bda5e33..b98418b 100644 --- a/slurp/masks/vegetationmask.py +++ b/slurp/masks/vegetationmask.py @@ -597,6 +597,22 @@ def clean_task( valid_stack = input_buffers[1][0] im_ndvi = input_buffers[2][0] + # Filter final mask with a NDVI threshold (1st cluster of vegetation) + # -> allows to have better shapes : pixels around a low veg area will be classified as bare ground + im_classif = np.where( + im_classif == LOW_VEG_CLASS, + np.where(im_ndvi > params["min_ndvi_veg"], LOW_VEG_CLASS, UNDEFINED_VEG+LOW_VEG_CLASS), + im_classif, + ) + # pixels around trees will be classified as middle texture + im_classif = np.where( + im_classif > LOW_VEG_CLASS, + np.where( + im_ndvi > params["min_ndvi_veg"], VEG_CODE + MIDDLE_TEXTURE_CODE, UNDEFINED_VEG+MIDDLE_TEXTURE_CODE + ), + im_classif, + ) + if params["remove_small_objects"]: high_veg_binary = np.where(im_classif > LOW_VEG_CLASS, True, False) high_veg_binary = apply_morpho( @@ -628,22 +644,7 @@ def clean_task( np.logical_and(im_classif > LOW_VEG_CLASS, low_veg_binary == 1) ] = LOW_VEG_CLASS - # Filter final mask with a NDVI threshold (1st cluster of vegetation) - # TODO : replace 0 by UNDEFINED_VEG ? - im_classif = np.where( - im_classif == LOW_VEG_CLASS, - np.where(im_ndvi > params["min_ndvi_veg"], LOW_VEG_CLASS, 0), - im_classif, - ) - # TODO : replace 0 by UNDEFINED_VEG + MIDDLE_TEXTURE_CODE - im_classif = np.where( - im_classif > LOW_VEG_CLASS, - np.where( - im_ndvi > params["min_ndvi_veg"], VEG_CODE + MIDDLE_TEXTURE_CODE, 0 - ), - im_classif, - ) - + im_classif = np.where(valid_stack == 0, im_classif, NODATA_INT8) return im_classif From a151d691170468dec417a5bb1652390ba47693b8 Mon Sep 17 00:00:00 2001 From: Yannick TANGUY Date: Wed, 25 Feb 2026 14:12:05 +0000 Subject: [PATCH 2/2] Fix regularization of vegetation : invert two steps and replace 0 by undefined_veg --- slurp/masks/vegetationmask.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/slurp/masks/vegetationmask.py b/slurp/masks/vegetationmask.py index b98418b..9be79df 100644 --- a/slurp/masks/vegetationmask.py +++ b/slurp/masks/vegetationmask.py @@ -598,21 +598,28 @@ def clean_task( im_ndvi = input_buffers[2][0] # Filter final mask with a NDVI threshold (1st cluster of vegetation) - # -> allows to have better shapes : pixels around a low veg area will be classified as bare ground + # -> allows to have better shapes : pixels around a low veg area will be + # classified as bare ground im_classif = np.where( im_classif == LOW_VEG_CLASS, - np.where(im_ndvi > params["min_ndvi_veg"], LOW_VEG_CLASS, UNDEFINED_VEG+LOW_VEG_CLASS), + np.where( + im_ndvi > params["min_ndvi_veg"], + LOW_VEG_CLASS, + UNDEFINED_VEG + LOW_VEG_CLASS, + ), im_classif, ) # pixels around trees will be classified as middle texture im_classif = np.where( im_classif > LOW_VEG_CLASS, np.where( - im_ndvi > params["min_ndvi_veg"], VEG_CODE + MIDDLE_TEXTURE_CODE, UNDEFINED_VEG+MIDDLE_TEXTURE_CODE + im_ndvi > params["min_ndvi_veg"], + VEG_CODE + MIDDLE_TEXTURE_CODE, + UNDEFINED_VEG + MIDDLE_TEXTURE_CODE, ), im_classif, ) - + if params["remove_small_objects"]: high_veg_binary = np.where(im_classif > LOW_VEG_CLASS, True, False) high_veg_binary = apply_morpho( @@ -644,7 +651,6 @@ def clean_task( np.logical_and(im_classif > LOW_VEG_CLASS, low_veg_binary == 1) ] = LOW_VEG_CLASS - im_classif = np.where(valid_stack == 0, im_classif, NODATA_INT8) return im_classif