xdem icon indicating copy to clipboard operation
xdem copied to clipboard

[POC] classif step 4: fusion classification

Open adebardo opened this issue 10 months ago • 0 comments

Context

After implementing the ClassificationLayer base class, we now need to develop the FusionClassificationLayer. This class handles the fusion of multiple classification layers, combining the results of individual classifications (e.g., slope and segmentation) into a fused classification. The fusion layer takes the outputs from other classification layers and creates a combined class mask.

The FusionClassificationLayer will inherit from the ClassificationLayer and implement the specific logic for fusing multiple classification layers.

Code

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

  1. __init__() method:
    • Extend the initialization from the ClassificationLayer.
    • Include additional attributes specific to fusion classification:
      • layers_to_fuse: A list of Mask objects that are being fused together (e.g., slope and segmentation layers).
      • layers_class_names: A list of dictionaries where each dictionary represents the class names of the layers being fused.
  2. apply_classification() method:
    • Combine the masks of the input classification layers using logical operations (e.g., intersection of masks) to create new fused classes.

    • Store the combined masks in the classification attribute, which is a geoutils.Mask 3D object, where the first dimension represents the fused class, and the two others represent the mask values. The number of bands in classification should be equal to the multiplication of the number of bands of all layers to fuse.

    • Store the fused class names under the class_names attribute, which will combine the class names of the fused layers.

      Example:

self.class_names = {
    "slope0_5_land": 0,
    "slope5_10_land": 1,
    "slope10_25_land": 2,
    "slope0_5_water": 1
    ...
}

Tests

  • Write unit tests for the FusionClassificationLayer 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