MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __init__

Method __init__

monai/transforms/intensity/array.py:2698–2727  ·  view source on GitHub ↗
(
        self,
        threshold: dict | Callable | str | float | int = "otsu",
        hsv_threshold: dict | Callable | str | float | int | None = None,
        invert: bool = False,
    )

Source from the content-addressed store, hash-verified

2696 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
2697
2698 def __init__(
2699 self,
2700 threshold: dict | Callable | str | float | int = "otsu",
2701 hsv_threshold: dict | Callable | str | float | int | None = None,
2702 invert: bool = False,
2703 ) -> None:
2704 self.thresholds: dict[str, Callable | float] = {}
2705 if threshold is not None:
2706 if isinstance(threshold, dict):
2707 for mode, th in threshold.items():
2708 self._set_threshold(th, mode.upper())
2709 else:
2710 self._set_threshold(threshold, "R")
2711 self._set_threshold(threshold, "G")
2712 self._set_threshold(threshold, "B")
2713 if hsv_threshold is not None:
2714 if isinstance(hsv_threshold, dict):
2715 for mode, th in hsv_threshold.items():
2716 self._set_threshold(th, mode.upper())
2717 else:
2718 self._set_threshold(hsv_threshold, "H")
2719 self._set_threshold(hsv_threshold, "S")
2720 self._set_threshold(hsv_threshold, "V")
2721
2722 self.thresholds = {k: v for k, v in self.thresholds.items() if v is not None}
2723 if self.thresholds.keys().isdisjoint(set("RGBHSV")):
2724 raise ValueError(
2725 f"Threshold for at least one channel of RGB or HSV needs to be set. {self.thresholds} is provided."
2726 )
2727 self.invert = invert
2728
2729 def _set_threshold(self, threshold, mode):
2730 if callable(threshold):

Callers

nothing calls this directly

Calls 1

_set_thresholdMethod · 0.95

Tested by

no test coverage detected