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

Handling of missing properties #89

Closed
ChristianMarzahl opened this issue Sep 28, 2023 · 8 comments
Closed

Handling of missing properties #89

ChristianMarzahl opened this issue Sep 28, 2023 · 8 comments

Comments

@ChristianMarzahl
Copy link

Dear authors,

Thank you very much for this helpful repository.

Observation

The conversion throws an exception if the PROPERTY_NAME_MPP_X value is not set in a tiff file.

    created_files = WsiDicomizer.convert(
                    ^^^^^^^^^^^^^^^^^^^^^
  /python3.11/site-packages/wsidicomizer/wsidicomizer.py", line 215, in convert
    with cls.open(
         ^^^^^^^^^
/python3.11/site-packages/wsidicomizer/wsidicomizer.py", line 137, in open
    return cls(source, label)
           ^^^^^^^^^^^^^^^^^^
/python3.11/site-packages/wsidicom/wsidicom.py", line 82, in __init__
    self._levels = Levels.open(source.level_instances)
                               ^^^^^^^^^^^^^^^^^^^^^^
/python3.11/site-packages/wsidicomizer/dicomizer_source.py", line 121, in level_instances
    return [
           ^
/python3.11/site-packages/wsidicomizer/dicomizer_source.py", line 123, in <listcomp>
    self._create_level_image_data(level_index),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/python3.11/site-packages/wsidicomizer/sources/tiffslide/tiffslide_source.py", line 93, in _create_level_image_data
    return TiffSlideLevelImageData(
           ^^^^^^^^^^^^^^^^^^^^^^^^
/python3.11/site-packages/wsidicomizer/sources/tiffslide/tiffslide_image_data.py", line 200, in __init__
    base_mpp_x = float(self._slide.properties[PROPERTY_NAME_MPP_X])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: float() argument must be a string or a real number, not 'NoneType'

Environment

OS: Linux (Ubuntu) 
22.04

wsidicomizer 0.10.2

Possible Solution

Could you set a default value for MPP to enable the conversion with missing values?

base_mpp_x = float(self._slide.properties[PROPERTY_NAME_MPP_X])

 base_mpp_x = float(self._slide.properties.get("PROPERTY_NAME_MPP_X", 1.0)

With kind regards,
Christian

@erikogabrielsson erikogabrielsson transferred this issue from imi-bigpicture/wsidicom Sep 28, 2023
@erikogabrielsson
Copy link
Collaborator

Hi @ChristianMarzahl and thanks for reporting this issue.

I have worked on a more flexible interface for providing metadata, were one can specify metadata that should override the metadata from the image file as well as metadata that should be used as default if no other metadata is available. This might be worth putting into that.

I dont now what the source file format is (if it is possible, please share the file)? As it is opened by the tiffslide reader, is it supported by tiffslide.?

@ChristianMarzahl
Copy link
Author

Dear @erikogabrielsson,

First of all, thank you very much for your quick response.
The file was created with the Philips SDK and was converted from .isyntax to TIFF. Unfortunately, I can't share the file, but I will try to create one I can share. It looks like the SDK is not storing any meta information in the resulting tiff file.

Regarding tiffslide:
Yes, the Python package can open the WSI and extract tiles.
image

Your flexible interface for setting meta data sounds excellent.

@erikogabrielsson
Copy link
Collaborator

Ho @ChristianMarzahl,

The development branches for adding more metadata functionality to wsidicom and wsidicomizer are here and here. With these changes, one can specify a base pixel spacing (either overriding or defaulting), see test.

If you are able to share a test image for from your converter I can test if this works. Otherwise you are free to test it yourself. There is still some work needed before this is released.

@ChristianMarzahl
Copy link
Author

Dear @erikogabrielsson,

Thank you for looking into this. It took a little bit longer to figure out that the attached file is anonymous enough to act as a demo I can provide to you:
https://drive.google.com/file/d/1nPwvexvbm-2f3rOzsLdNkkumGe-vhVxV/view?usp=sharing

The WSI was converted with Philips SDK from .isyntax to TIFF. We saw this exception with all the examples.

With kind regards,
Christian

@erikogabrielsson
Copy link
Collaborator

Thanks for sharing @ChristianMarzahl. I will look into this as soon as possible.

Is the philips converter avaiable somewhere?

@ChristianMarzahl
Copy link
Author

Dear @erikogabrielsson,

Yes: https://www.usa.philips.com/healthcare/sites/pathology/about/sdk

By the way. Thank you very much for updating the wsidicomizer.

With kind regards,
Christian

@erikogabrielsson
Copy link
Collaborator

erikogabrielsson commented Dec 21, 2023

Hi @ChristianMarzahl

Short update on this. Using the new metadata feature in wsidicom and wsidicomizer one can insert missing or override properties, such as pixel spacing:

from wsidicom.geometry import SizeMm
from wsidicom.metadata.image import Image
from wsidicomizer import WsiDicomizer
from wsidicomizer.metadata import WsiDicomizerMetadata

input_file = Path(r'C:\research_data\ISyntaxToTiff.tiff')

image =  Image(pixel_spacing=SizeMm(0.00025, 0.00025))
metadata = WsiDicomizerMetadata(image=image)

with WsiDicomizer.open(input_file, default_metadata=metadata) as wsi:
    print(f"wsi of size: {wsi.mm_size} and pixel spacing {wsi.pixel_spacing}")
    region = wsi.read_region_mm((0, 8), 6, (10, 10))
region

And get:

wsi of size: SizeMm(width=24.064, height=22.784) and pixel spacing SizeMm(width=0.00025, height=0.00025)

image

This is unfortunately not ready for release, as Im waiting for highdicom to support Python 3.12. You can however test the feature by installing from git:

  • First do git clone on both repositories. The repositories much be in the same folder.
  • Run pip install . in the wsidicomizer folder.

@erikogabrielsson
Copy link
Collaborator

Fixed in 0.12.0. Metadata such as pixel spacing can now be specified if missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants