diff --git a/wsidicom/codec/encoder.py b/wsidicom/codec/encoder.py index b744d65..deb9d91 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 diff --git a/wsidicom/metadata/image.py b/wsidicom/metadata/image.py index 832c53a..6eeb842 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)