Repository: Project-MONAI/MONAI
File: monai/apps/deepedit/transforms.py (Python)

Code before:
            # Dictionary containing new label numbers
            new_label_names = {}
            label = np.zeros(d[key].shape)

            # Sort label names to ensure deterministic ordering (exclude background)
            sorted_labels = sorted(
                [(k, v) for k, v in self.label_names.items() if k != "background"]
            )

            # Always set background to 0 first
            if "background" in self.label_names:
                new_label_names["background"] = 0

            # Assign sequential indices to sorted non-background labels
            for idx, (key_label, val_label) in enumerate(sorted_labels, start=1):
                new_label_names[key_label] = idx
                label[d[key] == val_label] = idx

            d["label_names"] = new_label_names
            if isinstance(d[key], MetaTensor):
                d[key].array = label
            else:
                d[key] = label
        return d


class NormalizeLabelsInDatasetd(RemapLabelsToSequentiald):
    """
    .. deprecated:: 1.5.0
        `NormalizeLabelsInDatasetd` is deprecated. Use :class:`RemapLabelsToSequentiald` instead.

    This class is maintained for backward compatibility. Please use RemapLabelsToSequentiald
    which better describes the transform's functionality.
    """

    def __init__(
        self, keys: KeysCollection, label_names: dict[str, int] | None = None, allow_missing_keys: bool = False
    ):
        warnings.warn(
            "NormalizeLabelsInDatasetd is deprecated and will be removed in a future version. "
            "Please use RemapLabelsToSequentiald instead, which better describes what the transform does: "
            "remapping label values to sequential indices (0, 1, 2, 3, ...).",
            DeprecationWarning,
            stacklevel=2,
        )
        super().__init__(keys, label_names, allow_missing_keys)


class SingleLabelSelectiond(MapTransform):

    def __init__(

Review comment (suggestion):
We should definitely mark the old name as deprecated but we should instead use the [deprecated](https://github.com/Project-MONAI/MONAI/blob/01711cf7e3af991aabc92cc3fdf4c0b65949e65e/monai/utils/deprecate_utils.py#L41) decorator for this. The deprecation is also since version 1.6.0 and will be removed in version 1.8.0

Code after:
            # Dictionary containing new label numbers
            new_label_names = {}
            label = np.zeros(d[key].shape)

            # Sort label names to ensure deterministic ordering (exclude background)
            sorted_labels = sorted([(k, v) for k, v in self.label_names.items() if k != "background"])

            # Always set background to 0 first
            if "background" in self.label_names:
                new_label_names["background"] = 0

            # Assign sequential indices to sorted non-background labels
            for idx, (key_label, val_label) in enumerate(sorted_labels, start=1):
                new_label_names[key_label] = idx
                label[d[key] == val_label] = idx

            d["label_names"] = new_label_names
            if isinstance(d[key], MetaTensor):
                d[key].array = label
            else:
                d[key] = label
        return d


@deprecated(since="1.6", removed="1.8", msg_suffix="Use `RemapLabelsToSequentiald` instead.")
class NormalizeLabelsInDatasetd(RemapLabelsToSequentiald):
    """
    .. deprecated:: 1.6.0
        `NormalizeLabelsInDatasetd` is deprecated and will be removed in version 1.8.0.
        Use :class:`RemapLabelsToSequentiald` instead.

    This class is maintained for backward compatibility. Please use RemapLabelsToSequentiald
    which better describes the transform's functionality.
    """

    pass


class SingleLabelSelectiond(MapTransform):

    def __init__(
        self, keys: KeysCollection, label_names: Sequence[str] | None = None, allow_missing_keys: bool = False
    ):
        """
        Selects one label at a time to train the DeepEdit

        Args:
            keys: The ``keys`` parameter will be used to get and set the actual data item to transform
            label_names: all label names
        """
        super().__init__(keys, allow_missing_keys)