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

DICOM reading multi-frame files does not always work #18

Open
almarklein opened this issue Nov 2, 2014 · 7 comments
Open

DICOM reading multi-frame files does not always work #18

almarklein opened this issue Nov 2, 2014 · 7 comments

Comments

@almarklein
Copy link
Member

The file dicom_file_2.dcm does not work. I am pretty sure that code has worked on some multi-frame data, but this one obviously does not, while it does work in PyDicom.

@rossant
Copy link

rossant commented Oct 23, 2015

I also have a DICOM dir with multiple sequences that cannot be read:

Reading DICOM (examining files): 235/235 files (100.0%)
  Found 5 correct series.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/cyrille/git/imageio/imageio/core/functions.py", line 419, in mvolread
    for im in reader:
  File "/home/cyrille/git/imageio/imageio/core/format.py", line 372, in iter_data
    i, n = 0, self.get_length()
  File "/home/cyrille/git/imageio/imageio/core/format.py", line 317, in get_length
    return self._get_length()
  File "/home/cyrille/git/imageio/imageio/plugins/dicom.py", line 133, in _get_length
    self._data = dcm.get_numpy_array()
  File "/home/cyrille/git/imageio/imageio/plugins/_dicom.py", line 382, in get_numpy_array
    value = self._read_undefined_length_value()
  File "/home/cyrille/git/imageio/imageio/plugins/_dicom.py", line 275, in _read_undefined_length_value
    raise EOFError("End of file reached before sequence "
EOFError: End of file reached before sequence delimiter found.

otherwise, any ideas on how to just extract a single series?

@almarklein
Copy link
Member Author

Sorry, not really. PyDicom might do it if you're lucky. Any chance for me to get my hands on that data? Or can you have a look?

A first simple check could be to check what file it chokes on. If this is some kind of meta file, we might be able to fix it by detecting that and skipping it. If it is a real file with data, we should make the plugin able to read it.

@rossant
Copy link

rossant commented Oct 23, 2015

pydicom didn't work because the file was compressed. I managed to uncompress it with gdcm --raw and then imageio worked.

@almarklein
Copy link
Member Author

Ok, good. Do you know how we can detect that, so we can give a more appropriate error?

@ivoflipse
Copy link

I just ran into the same problem using pydicom and had hoped that imageio would have been able to read the data (alas it did not).

pydicom returns a helpful error saying which UID wasn't supported:
RuntimeError: The simple dicom reader can only read files with uncompressed image data (not u'1.2.840.10008.1.2.4.90')
Which according to this page is a JPEG 2000 Image Compression (Lossless Only).

I reckon it would be easier to have the plugin add pydicom as an optional dependency to imageio or have people pass along a pydicom object, from which you can ask whatever you want.

In the end I ended up opening it with GDCM, but I'd rather not depend on that. So any hints on what would need to happen to make similar functionality available in imageio?

@almarklein
Copy link
Member Author

Firstly, the dicom plugin needs better error reporting on this.

The dicom plugin in imageio was made standalone because at the time of writing pydicom was not available in py3k. It actually uses almost the same code. The extra code in pydicom is for 95% or so aimed at reading all the fancy tags, and for writing dicom files. At some point imageio would need a solution to allow reading more/all tags from the data though.

The problem with JPEG 2000 is that (afaik) there is no way to decode it from pure Python. There are libs/programs that can, so we might look into a solution like "please install X to read JPEG 2000" files, where X can be GDCM, DCMTK, or maybe even libjpeg.

@almarklein
Copy link
Member Author

@rossant i suspect that the issue that you saw was due to a bug where the reader tried to read a specific JPEG format.

@ivoflipse the error message is now a bit more clear

I added primitive funtionality to try to recover the dcmtkdjpeg executable (from Office dcmtk) and use it to convert the image on the fly. This is something that should probably extended in the future, but this is a start.

For the record, the original issue of not being able to load multi-page images still stands, AFAIK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants