DICOM reading multi-frame files does not always work
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.
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?
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.
pydicom didn't work because the file was compressed. I managed to uncompress it with gdcm --raw and then imageio worked.
Ok, good. Do you know how we can detect that, so we can give a more appropriate error?
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?
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.
@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.