imi-bigpicture / wsidicomizer

Python library for converting WSI files to DICOM
Apache License 2.0
57 stars 8 forks source link

Unable to convert some Openslide file formats #84

Closed fw-ashmistry closed 9 months ago

fw-ashmistry commented 1 year ago

I'm unable to convert some Openslide file formats to DICOM. I've installed the openslide extra so it could support the additional file formats. However out of those, I am only able to convert Leica data (along with Generic Tiff, SVS, ndpi, Zeiss czi). I'm using data from Openslide . It's just odd that with the openslide extra I can only convert Lecia.

The error message that I get is: is not supported

I have containerized this, using python:3.8-slim as the base with the latest versions of openslide-tools, python3-openslide, libturbojpeg0 and the following installed through pip:

wsidicom==0.10.0
opentile==0.10.0
numpy==1.22.0
pydicom==2.3.0
highdicom==0.20.0
czifile==2019.7.2
imagecodecs==2022.12.24
python-dateutil==2.8.2
tiffslide==2.1.1
wsidicomizer==0.10.1
erikogabrielsson commented 1 year ago

Hi @ashmistry36 and thanks for reporting this issue. To avoid misunderstanding, is your intent to force WsiDicomizer to use OpenSlide to read the files? As most of the formats you lists are by default not read by OpenSlide (but by OpenTile or the zeiss-reader).

The error you receive comes from:

raise NotImplementedError(f"{filepath} is not supported")

Here I assume you are also getting the actual used filepath (but have removed that in your report)?

fw-ashmistry commented 1 year ago

Just trying to convert, for example I am using the provided code (for initial testing I am just altering path_to_wsi_file).

from wsidicomizer import WsiDicomizer
created_files = WsiDicomizer.convert(
    path_to_wsi_file,
    path_to_output_folder,
    [device_module, specimen_module, optical_module, patient_module, study_module],
    tile_size
)

So are you saying that it's an issue with OpenTile then?

erikogabrielsson commented 1 year ago

Not sure. The default behavior is to first check if OpenTile can open the file, then TiffSlide, CziFile, and if installed OpenSlide. All of OpenTile, TiffSlide, and OpenSlide should be able to open all the formats you list except czi (Edit: OpenTile cant open Leica scn).

If you get the NotImplementedError all of those readers failed to open the file.

erikogabrielsson commented 1 year ago

You can test if the sources can open your file with:

from opentile import OpenTile
from tiffslide import TiffSlide
from wsidicomizer.sources.czi.czi_image_data import CziImageData
from openslide import OpenSlide

OpenTile.detect_format(filepath)
TiffSlide.detect_format(filepath)
CziImageData.detect_format(filepath)
OpenSlide.detect_format(str(filepath))
erikogabrielsson commented 1 year ago

@ashmistry36 Did you succeed in opening the files?

fw-ashmistry commented 1 year ago

Yes most of them. Openslide module wasn't installed in my container. Which is odd since I thought that'd be covered by apt-get install -y openslide-tools python3-openslide libturbojpeg0

I tried to get it installed through pip install openslide-python but that's causing some issues in building the image. So just trying to get that resolved. Will update here once I've figured that out.

erikogabrielsson commented 1 year ago

I typically use: apt-get install -y libturbojpeg libopenslide0 for docker images.

fw-ashmistry commented 1 year ago

Would you be able to share your requirements.txt and relevant parts of your Dockerfile? So I can get from openslide import OpenSlide imported fine?

erikogabrielsson commented 1 year ago

Here is a docker file that can be used to run wsidicomizer as cli.

You want a base image that has libjpeg turbo >= 2.1 in packages, or alternatively install it directly.

erikogabrielsson commented 1 year ago

Have you managed to solve this issue? Otherwise, maybe ensure that your input filepath exists and is a file before opening with WsiDicomizer, like:

if not Path(filepath).is_file():
    raise ValueError(f"File {filepath} does not exists or is not a file")
with WsiDicomizer.open(filepath) as wsi:
    ....
fw-ashmistry commented 1 year ago

I havn't gotten to this yet, but when I do I'll update here

erikogabrielsson commented 9 months ago

Closing this due to no updates for a while. If you still have issues after testing again, please re-open the issue.