Skip to content

Improve support to create an ImageFileReader from a DicomFileLike object (i.e. from a byte stream) #294

@gpizaine

Description

@gpizaine

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()), the read_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 function read_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 :)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions