DICOM: Add support for nested sequences #2558
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This fixes #2534.
The DICOM code was not handling sequences, which are like folders. Inside a sequence/folder, attributes like the image dimensions can be changed, but these only apply to images within the sequence/folder. Once exiting the sequence and returning to the parent "folder", the previous image attributes must be restored.
Issue #2534 has a sample image file that initially sets the image dimensions to 2101x2101, however it then begins a sequence for a thumbnail, which sets the dimensions to 64x64 and has some pixel data. After exiting that sequence, the original image dimensions are meant to be restored, however this was not happening. As a result the main image was read as 64x64 and the unused pixel data was then treated as further DICOM header information for a subsequent image, causing unrelated errors.
This PR uses ImageMagick's linked list implementation to push the relevant image attributes onto a stack each time a sequence is encountered, so that when the sequence is exited, the original attributes are restored. It fixes the issue and allows the sample image to be read correctly (both the thumbnail and the main image).