imi-bigpicture / wsidicomizer

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

WsiDicomizer stores DICOM with NumberOfSamples = 3, but should be 4 when converting from OpenSlide #10

Closed GeertLitjens closed 2 years ago

GeertLitjens commented 2 years ago

Took me a while to figure this out, but when converting from OpenSlide and encoding to JPEG2000, the DICOM Tag SamplesPerPixel is set to 3, however, OpenSlide is returning ARGB and this is also stored in the JPEG2000-encoded. This makes it challenging to allocate the correct buffers in third-party applications. There are two solutions, which is why I didn't fix it myself:

  1. Strip the alpha part from the returned openslide tile
  2. Store the SamplesPerPixel as 4

As I don't know very well if DICOM handles an alpha channel very well, I thought stripping it might be better?

erikogabrielsson commented 2 years ago

Thanks for the bug report. Yes the openslide data comes as ARGB. The jpeg-encoder can handle (ignore) the extra channel by setting the input color space. I have to test if the jpeg2000 does the same (there is a colorspace flag). Otherwise we must strip it before sending it to the encoder. It is not allowed to have anything else than 1 or 3 SamplesPerPixel.