xdem icon indicating copy to clipboard operation
xdem copied to clipboard

[POC] classif step 3: segmentation classification

Open adebardo opened this issue 10 months ago • 0 comments

Context

After implementing the ClassificationLayer base class, the next step is to develop the SegmentationClassificationLayer. This class handles segmentation-based classification of a DEM, where it classifies DEM pixels based on an external segmentation mask provided by the user.

The SegmentationClassificationLayer will inherit from the ClassificationLayer and will implement the logic for applying the segmentation mask to the DEM.

Code

In the same file (classification.py) as the ClassificationLayer base class, add the SegmentationClassificationLayer to define the segmentation classification logic.

  1. __init__() method:
    • Extend the initialization from the ClassificationLayer.
    • Include additional attributes specific to segmentation classification:
      • segmentation_mask_path: A string that represents the path to the external segmentation mask (e.g., a raster file).
      • class_names: A dictionary that maps class names to values in the segmentation mask (e.g., {"valid": 1, "water": 2, "land": 3}). Could be a YAML file too.
  2. apply_classification() method:
    • Load the segmentation mask from the file specified in segmentation_mask_path.
    • For each class defined in class_names, create a mask where DEM pixels match the segmentation values.
    • Store the resulting masks in the classification attribute, which is a geoutils.Mask 3D object, where the first dimension represents the class, and the two others represent the mask values.

Tests

  • Write unit tests for the SegmentationClassificationLayer class in test_classification.py file.
  • The unit tests should:
    1. Verify that the layer initializes properly with the provided configuration.
    2. Ensure that the classification logic works as expected.
    3. Confirm that statistics are computed as expected.
    4. Validate that the results are saved correctly.

adebardo avatar Mar 03 '25 08:03 adebardo