Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spelling and doc-strings for ImageCoordinateSystem #164

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions wsidicom/codec/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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
Expand Down
45 changes: 44 additions & 1 deletion wsidicom/metadata/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand Down