From 2ec71ee6d329e27ff11da5cd25cc4378acd6c802 Mon Sep 17 00:00:00 2001 From: Erik O Gabrielsson Date: Mon, 22 Jul 2024 13:14:07 +0200 Subject: [PATCH 1/2] Fix spelling and doc-strings for ImageCoordinateSystem --- wsidicom/metadata/image.py | 45 +++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/wsidicom/metadata/image.py b/wsidicom/metadata/image.py index 832c53ae..6eeb842c 100644 --- a/wsidicom/metadata/image.py +++ b/wsidicom/metadata/image.py @@ -69,6 +69,20 @@ def orientation(self) -> Orientation: return Orientation.from_rotation(self.rotation) def image_to_slide(self, image: GeometryType) -> GeometryType: + """Translate a geometry (PointMm or RegionMm) from image coordinate system + (origin at image top-left corner) to slide coordinate system (origin at + slide corner). + + Parameters + ---------- + image : GeometryType + The geometry to translate. + + Returns + ------- + GeometryType + The translate geometry. + """ if isinstance(image, PointMm): offset = self.orientation.apply_transform(image) return self.origin + offset @@ -77,6 +91,20 @@ def image_to_slide(self, image: GeometryType) -> GeometryType: return RegionMm(start, SizeMm(end.x - start.x, end.y - start.y)) def slide_to_image(self, slide: GeometryType) -> GeometryType: + """Translate a geometry (PointMm or RegionMm) from slide coordinate system + (origin at slide corner) to image coordinate system (origin at image top-left + corner). + + Parameters + ---------- + slide : GeometryType + The geometry to translate. + + Returns + ------- + GeometryType + The translate geometry. + """ if isinstance(slide, PointMm): offset = slide - self.origin return self.orientation.apply_reverse_transform(offset) @@ -89,9 +117,24 @@ def slide_to_image(self, slide: GeometryType) -> GeometryType: size = SizeMm(end.x - start.x, end.y - start.y) return RegionMm(start, size) - def to_other_corrdinate_system( + def to_other_coordinate_system( self, other: "ImageCoordinateSystem", image: GeometryType ) -> GeometryType: + """Translate a geometry (PointMm or RegionMm) from this image coordinate system + to another image coordinate system. + + Parameters + ---------- + other : ImageCoordinateSystem + The target image coordinate system. + image : GeometryType + The geometry to translate. + + Returns + ------- + GeometryType + The translate geometry. + """ slide = self.image_to_slide(image) return other.slide_to_image(slide) From 2a6010eb367253af0dab21c6dae81a42b0f19959 Mon Sep 17 00:00:00 2001 From: Erik O Gabrielsson Date: Thu, 25 Jul 2024 18:19:25 +0200 Subject: [PATCH 2/2] Typing fix --- wsidicom/codec/encoder.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/wsidicom/codec/encoder.py b/wsidicom/codec/encoder.py index b744d65d..deb9d912 100644 --- a/wsidicom/codec/encoder.py +++ b/wsidicom/codec/encoder.py @@ -183,12 +183,16 @@ def create( Parameters ---------- - settings: SettingsType - Settings for the encoder. + transfer_syntax: UID + Transfer syntax UID. + bits: int + Number of bits per sample. + photometric_interpretation: str + Photometric interpretation. Returns ------- - Encoder[SettingsType] + Encoder Encoder for settings. """ settings = Settings.create( @@ -199,17 +203,17 @@ def create( return cls.create_for_settings(settings) @classmethod - def create_for_settings(cls, settings: SettingsType) -> "Encoder[SettingsType]": + def create_for_settings(cls, settings: Settings) -> "Encoder": """Create an encoder using settings. Parameters ---------- - settings: SettingsType + settings: Settings Settings for the encoder. Returns ------- - Encoder[SettingsType] + Encoder Encoder for settings. """ encoder = cls._select_encoder(settings) @@ -219,18 +223,18 @@ def create_for_settings(cls, settings: SettingsType) -> "Encoder[SettingsType]": @staticmethod def _select_encoder( - settings: SettingsType, - ) -> Optional["Type[Encoder[SettingsType]]"]: + settings: Settings, + ) -> Optional["Type[Encoder]"]: """Select encoder for settings. Parameters ---------- - settings: SettingsType + settings: Settings Settings for the encoder. Returns ------- - Optional[Type[Encoder[SettingsType]]] + Optional[Type[Encoder]] Encoder for settings, or None if no encoder is available. """ # Sort encoders by preference