-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Hey there,
I'm trying to read a DICOM file from a byte stream (context: I'm downloading just enough data from large remote DICOM files of several gigabytes to read metadata only), something like:
highdicom.io.ImageFileReader(pydicom.filebase.DicomFileLike(bytes_io))
but faced a few errors. As it's not a common use case, it could be that some code paths are not fully up-to-date.
I've done some investigations and found at least two issues in the ImageFileReader
class (io.py). I'm just using highdicom to read metadata, so I can't speak for the whole library, there might be more issues lurking elsewehere:
-
On line 69,
tag = TupleTag(fp.read_tag())
, theread_tag
function does not exist in released pydicom versions (2.4 at the time of this writing) but appears in 3.0.0.dev0. Replacing it with the equivalent functionread_be_tag
from pydicom 2.4 seems to work. -
After reading the metadata with pydicom in
_read_metadata()
, the code checks whether the next tag is a well-known Pixel Data tag by comparing it to hard-coded values (link)
_FLOAT_PIXEL_DATA_TAGS = {0x7FE00008, 0x7FE00009, }
_UINT_PIXEL_DATA_TAGS = {0x7FE00010, }
_PIXEL_DATA_TAGS = _FLOAT_PIXEL_DATA_TAGS.union(_UINT_PIXEL_DATA_TAGS)
In my case, the Pixel Data tag is (0xE07F, 0x1000)
, an endianness away from the hard-coded value. Manually adding 0xE07F1000
as a candidate in _UINT_PIXEL_DATA_TAGS
solves the issue.
I don't know how much effort is required, but it would be great to improve the support of DicomFileLike objects!
PS: thanks for the amazing library btw :)