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

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

Open
gpizaine opened this issue Jun 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@gpizaine
Copy link

gpizaine commented Jun 19, 2024

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 :)

@CPBridge
Copy link
Collaborator

Hi @gpizaine,

Thanks for reporting this issue. I may be wrong here, but I think the issue here is not so much the support for DicomFileLike as the support from reading Big Endian transfer syntaxes in general. Since Big Endian transfer syntaxes have been retired from the standard for a while, and working with them is in general really a pain, we took the decision a while ago not to put the effort into support them. See this comment in the release notes.

Could you please confirm what the transfer syntax of your file is? And also whether the issue is resolved by converting it to a little endian transfer syntax (e.g. like this post).

I'm not totally opposed to small changes that would allow things to work with big endian files, but trying to understand the scope of the problem first. Thanks

@CPBridge CPBridge self-assigned this Jun 21, 2024
@CPBridge CPBridge added the bug Something isn't working label Jun 21, 2024
@CPBridge
Copy link
Collaborator

Oh, also, does this work with the same file if you pass the same file as a path, not a DicomFileLike?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants