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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix loading of DICOM files with no preamble #1153

Conversation

cpinter
Copy link
Contributor

@cpinter cpinter commented Aug 9, 2019

The fix consists of two parts:

  • In DCMTK and GDCM ImageIO there are two duplicate functions called readNoPreambleDicom. Its implementation was faulty, as it did not consider the two bytes that were already read but rejected as it was not a VR (value representation). These two bytes are now reused for the length, which is now correctly read, which confirms that the order of information in the DICOM header is correct. This function was fixed both places
  • In DCMTK file reader CanReadFile function the loadFile call confirms that the file is valid despite not having a preamble, in which case it returns an EC_FileMetaInfoHeaderMissing value instead of an EC_Normal. This value needs to be accepted as well

This change can be tested on the datasets mentioned in this SlicerRT issue: SlicerRt/SlicerRT#49
The datasets in question are: aw-4.4-foot (CT, scout), corvus-6.2.2-phantom (CT, dose, RT images), xio-4.33.02-phantom-chest, xio-4.60.00-phantom-chest/t50, (CT, dose), xio-4.60.00-* (CT, dose, RT image), xio-4.64-phantom-prostate-beams-* (CT, dose)
Which can be found here: https://pocus.cs.queensu.ca/#collection/5cc8811601d4930406c40465 or here https://github.com/SlicerRt/SlicerRtData/tree/master

PR Checklist

Refer to the ITK Software Guide for
further development details if necessary.

@cpinter
Copy link
Contributor Author

cpinter commented Aug 9, 2019

@hjmjohnson Please hang on, maybe I overrode previous changes. Sorry!

The fix consists of two parts:
- In DCMTK and GDCM ImageIO there are two duplicate functions called readNoPreambleDicom. Its implementation was faulty, as it did not consider the two bytes that were already read but rejected as it was not a VR (value representation). These two bytes are now reused for the length, which is now correctly read, which confirms that the order of information in the DICOM header is correct. This function was fixed both places
- In DCMTK file reader CanReadFile function the loadFile call confirms that the file is valid despite not having a preamble, in which case it returns an EC_FileMetaInfoHeaderMissing value instead of an EC_Normal. This value needs to be accepted as well

This change can be tested on the datasets mentioned in this SlicerRT issue: SlicerRt/SlicerRT#49
The datasets in question are: aw-4.4-foot (CT, scout), corvus-6.2.2-phantom (CT, dose, RT images), xio-4.33.02-phantom-chest, xio-4.60.00-phantom-chest/t50, (CT, dose), xio-4.60.00-* (CT, dose, RT image), xio-4.64-phantom-prostate-beams-* (CT, dose)
Which can be found here: https://pocus.cs.queensu.ca/#collection/5cc8811601d4930406c40465 or here https://github.com/SlicerRt/SlicerRtData/tree/master
@cpinter cpinter force-pushed the fix-dicom-loading-without-preamble branch from 0139530 to dc89b5b Compare August 9, 2019 21:00
@cpinter
Copy link
Contributor Author

cpinter commented Aug 9, 2019

I thought I checked all files, but apparently not. Fixed now!

@hjmjohnson
Copy link
Member

@cpinter Thank you. Is there any chance a test could be added? Is one of these data sets suitable for creating a test of this code? That would ensure that future changes would also be able to read those files.

Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep in mind support for both big endian and little endian.

As Hans said, you seem to have the data, so it would be nice if you added the smallest such image as a read test. That is not a blocker, though.

Modules/IO/DCMTK/src/itkDCMTKImageIO.cxx Show resolved Hide resolved
Modules/IO/GDCM/src/itkGDCMImageIO.cxx Show resolved Hide resolved
@hjmjohnson
Copy link
Member

@cpinter @pieper @lassoan THANK YOU for investigatting this issue. I think it is 90% there. The two outstanding issues that need to be addressed to get this into ITK robustly for the future:

  • Reference test to validate correct results into the future (not strictly required, but it sure would be nice so that we don't revisit this issue in the future).
  • address concerns about big/little endedness

@cpinter
Copy link
Contributor Author

cpinter commented Aug 11, 2019

Thank you! I intend to take care of these tomorrow.

@cpinter
Copy link
Contributor Author

cpinter commented Aug 12, 2019

  1. I tried loading both liettle and big endian files, and they were loaded fine.
  2. I'm adding very simple tests that load an 8KB test file with DCMTK and GDCM. What is the proper way to add data files so that it appears in ExternalData?

@cpinter
Copy link
Contributor Author

cpinter commented Aug 12, 2019

The tests work, but I still don't know how to add ExternalData. I tried to follow this
https://itk.org/Wiki/ITK/Git/Develop/Data#ExternalData
but the "CMake will move the original file" step did not happen. I cannot see anything in my Kitware Girder (yes, I added the API key). Help would be appreciated, thanks!

Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two test can be merged, and have the instantiated IO depend on a command-line argument.

Modules/IO/DCMTK/src/itkDCMTKImageIO.cxx Show resolved Hide resolved
@dzenanz
Copy link
Member

dzenanz commented Aug 13, 2019

The link you looked at is outdated. New content is here:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/Data.md

@dzenanz
Copy link
Member

dzenanz commented Aug 13, 2019

... and a more direct link:
https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/UploadBinaryData.md

@cpinter
Copy link
Contributor Author

cpinter commented Aug 13, 2019

The two test can be merged, and have the instantiated IO depend on a command-line argument.

I would rather not spend more time on this than absolutely necessary, as I have several projects waiting for me. The tests cover the necessary cases, so this change would be only cosmetic (and I'm not sure where the common test should go, since I wouldn't put a GDCM test in DCMTK project or vice versa). Please let me know if it's OK like this.

@dzenanz
Copy link
Member

dzenanz commented Aug 13, 2019

Uh, I didn't realize they need to be in different subprojects. Keep it as-is then.

@cpinter cpinter force-pushed the fix-dicom-loading-without-preamble branch from c1f4139 to 4a5eb27 Compare August 13, 2019 14:15
@cpinter cpinter force-pushed the fix-dicom-loading-without-preamble branch from 4a5eb27 to 935cfb7 Compare August 13, 2019 14:44
@cpinter
Copy link
Contributor Author

cpinter commented Aug 13, 2019

I added and tested the download of the external data input file (8.3K dcm file) for these tests. I did a clean build and the tests pass. I updated the PR, I think it should be good to go.
Thanks for the fast reviews!

Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@lassoan
Copy link
Contributor

lassoan commented Aug 13, 2019

@dzenanz, it would be nice if you could add a big red warning to https://itk.org/Wiki/ITK/Git/Develop/Data#ExternalData that instructions are outdated and add a link to the current instructions.

You could even replace the entire text of the page with links to relevant sections of current documentation because the page right now is not useful but potentially misleading for developers (and old content can be always retrieved from the page's history).

@cpinter
Copy link
Contributor Author

cpinter commented Aug 13, 2019

There is a warning on the top but I missed it so probably something bigger and redder would be useful, I agree :)

@dzenanz
Copy link
Member

dzenanz commented Aug 13, 2019

... replace the entire text of the page with links ...

Done!

@lassoan
Copy link
Contributor

lassoan commented Aug 13, 2019

Perfect, thank you!

@dzenanz dzenanz merged commit 08c7b17 into InsightSoftwareConsortium:master Aug 13, 2019
@cpinter
Copy link
Contributor Author

cpinter commented Aug 13, 2019

Excellent, thanks a lot!

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

Successfully merging this pull request may close these issues.

None yet

4 participants