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

Failed to import DICOM (containing JPG slices) #36

Closed
chiaradivece opened this issue Nov 24, 2020 · 10 comments
Closed

Failed to import DICOM (containing JPG slices) #36

chiaradivece opened this issue Nov 24, 2020 · 10 comments

Comments

@chiaradivece
Copy link
Contributor

Hi! First, thanks for this amazing work! I'm struggling to import DICOM models. I have a folder with .dcm files (each one corresponding to a CT slice). When I select the folder in which the files are, I get this error:

InvalidCastException: Specified cast is not valid.
System.Convert.ToInt32 (System.Object value) (at <9577ac7a62ef43179789031239ba8798>:0)
UnityVolumeRendering.DICOMImporter.ToPixelArray (openDicom.Image.PixelData pixelData) (at Assets/Scripts/Importing/DICOMImporter.cs:202)
UnityVolumeRendering.DICOMImporter.Import () (at Assets/Scripts/Importing/DICOMImporter.cs:94)
UnityVolumeRendering.VolumeRendererEditorFunctions.ShowDICOMImporter () (at Assets/Editor/VolumeRendererEditorFunctions.cs:30)

I've also tried with another dataset, and the error is this:

Problems processing the DICOM file /Users/chiara/Downloads/TRAUMA/trauma0730.dcm :
System.ArgumentException: Item has already been added. Key in dictionary: '(0002,0002)' Key being added: '(0002,0002)'
at System.Collections.Hashtable.Insert (System.Object key, System.Object nvalue, System.Boolean add) [0x001d4] in <9577ac7a62ef43179789031239ba8798>:0
at System.Collections.Hashtable.Add (System.Object key, System.Object value) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0
at openDicom.DataStructure.DataSet.DataSet.Add (openDicom.DataStructure.DataSet.DataElement dataElement) [0x00009] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/DataStructure/DataSet/DataSet.cs:113
at openDicom.DataStructure.DataSet.DataSet.Add (openDicom.DataStructure.DataSet.DataSet dataSet) [0x00017] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/DataStructure/DataSet/DataSet.cs:126
at openDicom.File.DicomFile.GetJointDataSets () [0x00014] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/File/DicomFile.cs:157
at openDicom.File.DicomFile.LoadFrom (System.IO.Stream stream) [0x00042] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/File/DicomFile.cs:133
at openDicom.File.AcrNemaFile..ctor (System.String fileName, System.Boolean useStrictDecoding) [0x00028] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/File/AcrNemaFile.cs:131
at openDicom.File.DicomFile..ctor (System.String fileName, System.Boolean useStrictDecoding) [0x00007] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/3rdparty/openDicom/File/DicomFile.cs:83
at UnityVolumeRendering.DICOMImporter.LoadFile (System.String filePath) [0x0000e] in /Users/chiara/GitHub/UnityVolumeRendering/Assets/Scripts/Importing/DICOMImporter.cs:180
UnityEngine.Debug:LogError(Object)
UnityVolumeRendering.DICOMImporter:LoadFile(String) (at Assets/Scripts/Importing/DICOMImporter.cs:188)
UnityVolumeRendering.DICOMImporter:ReadDICOMFile(String) (at Assets/Scripts/Importing/DICOMImporter.cs:125)
UnityVolumeRendering.DICOMImporter:Import() (at Assets/Scripts/Importing/DICOMImporter.cs:61)
UnityVolumeRendering.VolumeRendererEditorFunctions:ShowDICOMImporter() (at Assets/Editor/VolumeRendererEditorFunctions.cs:30)

I tried to open the datasets in a DICOM visualization system and they seem just fine. Many thanks in advance!

@mlavik1
Copy link
Owner

mlavik1 commented Nov 25, 2020

Hi! Thanks for reporting this issue.

Do you know if your dataset uses JPEG format?
I think there is a mistake in how I'm handling DICOM sequences. I managed to fix the issue, but then I encountered another issue: Many DICOM files that use JPEG don't have a JPEG header, so I'm not able to import the JPEG bytes properly. I'm not sure how I'll fix this, but I'll keep looking into it. (@MusoAga maybe you know?)

By the way, is this an open dataset that you can share with me?
If not, I seem to have one dataset where I can reproduce the same issue :)
But the files I am testing with also don't work in ImageVis3D, so it might still work with your dataset if we are lucky! So if it's possible for you to send me the dataset then that would be great 👍

@chiaradivece
Copy link
Contributor Author

chiaradivece commented Nov 25, 2020

Hi @mlavik1,
Thanks for the prompt reply!
I'm not sure about the format; however, the first dataset I was testing is available. You can download it from the DICOM Library website at this link: https://www.dicomlibrary.com/meddream/?study=1.2.826.0.1.3680043.8.1055.1.20111102150758591.92402465.76095170

Thanks for the help!

@mlavik1
Copy link
Owner

mlavik1 commented Nov 25, 2020

@chiaradivece Thanks for sharing!
I did a quick test, and it seems to be the same problem. The dataset contains JPEG data without a header.
I will try to add support for this, but it might take some time (since I have less time for personal projects now), but I'll do my best!

For now, you can import your dataset if you export it as an image sequence like this:
image
(I used JPEG, but all of them should work)
And then you can import it into Unity by clicking this button instead:
image
The quality might be better with DICOM, but I did a test and your dataset looks like this (after eding the TF and enabling lighting):
image
And this is with maximum intensity projection:
image

I'll let you know if/when I have fixed the DICOM issue.
DICOM files that do not use JPEG should work though :)

@chiaradivece
Copy link
Contributor Author

Many thanks, @mlavik1! It works with png!

@mlavik1
Copy link
Owner

mlavik1 commented Nov 27, 2020

@chiaradivece Good to hear!
I will keep this task open (but change the description) until I have done a fix for DICOM with JPG.
Have a nice day!

@mlavik1 mlavik1 changed the title Import .dcm files Failed to import DICOM (containing JPG slices) Nov 27, 2020
@chiaradivece
Copy link
Contributor Author

Hey @mlavik1, I wanted to point out another problem. I tried to upload another DICOM dataset (it works fine when I try to open in Slicer or similar). However, I get the following error:

Insufficient number of slices.
UnityEngine.Debug:LogError(Object)
UnityVolumeRendering.DICOMImporter:Import() (at Assets/Scripts/Importing/DICOMImporter.cs:72)
UnityVolumeRendering.VolumeRendererEditorFunctions:ShowDICOMImporter() (at Assets/Editor/VolumeRendererEditorFunctions.cs:30)

@mlavik1
Copy link
Owner

mlavik1 commented Nov 28, 2020

Hello again!
Hmm.. is there another error before that error?
I suspect that it failed to import one or more slices, but if that's the case there should also be more errors in the log.

Also, is this a dataset that can be shared?

@chiaradivece
Copy link
Contributor Author

Hi @mlavik1! Mmm no, this is the first error that appears. I could try to share it with you. Thanks

@mlavik1
Copy link
Owner

mlavik1 commented Nov 28, 2020

Thanks @chiaradivece ! That would be great.

@mlavik1
Copy link
Owner

mlavik1 commented Apr 7, 2022

Fixed by #95
The dataset can now be imported with SimpleITK (on Windows only for now).
bilde

@mlavik1 mlavik1 closed this as completed Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants