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

Parse philips tiff mettadata #80

Merged
merged 2 commits into from
Nov 29, 2023
Merged
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
33 changes: 33 additions & 0 deletions tiffslide/tiffslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Iterator
from typing import Literal
from typing import Mapping
from typing import Optional
from typing import TypeVar
from typing import overload
from warnings import warn
Expand Down Expand Up @@ -644,6 +645,7 @@ class _PropertyParser:
scn="leica",
bif="ventana",
ndpi="hamamatsu",
philips="philips_tiff"
# add more when needed
)

Expand Down Expand Up @@ -843,6 +845,37 @@ def parse_generic_tiff(self) -> dict[str, Any]:
md.update(self.collect_level_info(series0))
return md

def parse_philips_tiff(self) -> dict[str, Any]:
"""parse Philips tiff properties"""
md = self.parse_generic_tiff()
if self._tf.philips_metadata is None:
return md
philips_metadata = ElementTree.fromstring(self._tf.philips_metadata)
def get_first_attribute_with_name(
root: ElementTree.Element,
name: str
) -> Optional[str]:
return next(
root.iterfind(f".//Attribute[@Name='{name}']")
).text
md[PROPERTY_NAME_VENDOR] = get_first_attribute_with_name(
philips_metadata,
'DICOM_MANUFACTURER'
)
pixel_spacing_attribute = get_first_attribute_with_name(
philips_metadata,
'DICOM_PIXEL_SPACING'
)
if pixel_spacing_attribute is not None:
pixel_spacings = [
float(element.strip('"')) * 1000
for element in pixel_spacing_attribute.split(' ')
]
mpp_x, mpp_y = pixel_spacings[0], pixel_spacings[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erikogabrielsson @ap-- i think x and y need to be reversed here. openslide's website says the following:

openslide.mpp-x
    calculated as 1000 * philips.DICOM_PIXEL_SPACING[1]
openslide.mpp-y
    calculated as 1000 * philips.DICOM_PIXEL_SPACING[0] 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. Per DICOM specifications the first value is the row spacing and the second value the column spacing,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i submitted a fix in #81

md[PROPERTY_NAME_MPP_X] = mpp_x
md[PROPERTY_NAME_MPP_Y] = mpp_y
return md


def _parse_metadata_aperio(desc: str) -> dict[str, Any]:
"""Aperio SVS metadata"""
Expand Down
Loading