diff --git a/monai/data/wsi_reader.py b/monai/data/wsi_reader.py index b31d4d9c3ab..96d84d8cf19 100644 --- a/monai/data/wsi_reader.py +++ b/monai/data/wsi_reader.py @@ -1098,7 +1098,7 @@ def get_mpp(self, wsi, level: int) -> tuple[float, float]: unit = wsi.pages[level].tags.get("ResolutionUnit") if unit is not None: unit = str(unit.value)[8:] - else: + if unit is None or len(unit) == 0: warnings.warn("The resolution unit is missing. `micrometer` will be used as default.") unit = "micrometer" diff --git a/monai/utils/misc.py b/monai/utils/misc.py index 96a59e1b355..e8a46ecc617 100644 --- a/monai/utils/misc.py +++ b/monai/utils/misc.py @@ -814,7 +814,7 @@ def __init__(self, input_unit: str, target_unit: str) -> None: "Both input and target units should be from the same quantity. " f"Input quantity is {input_base} while target quantity is {target_base}" ) - self._calculate_conversion_factor() + self.conversion_factor = self._calculate_conversion_factor() def _get_valid_unit_and_base(self, unit): unit = str(unit).lower() @@ -841,7 +841,7 @@ def _calculate_conversion_factor(self): return 1.0 input_power = self._get_unit_power(self.input_unit) target_power = self._get_unit_power(self.target_unit) - self.conversion_factor = 10 ** (input_power - target_power) + return 10 ** (input_power - target_power) def __call__(self, value: int | float) -> Any: return float(value) * self.conversion_factor