Page MenuHomePhabricator

Reformatting of Tilted Gantry series in DICOMSeriesReader
Closed, ResolvedPublic

Description

At the moment we handle tilted gantry series as single slice volumes instead of one volume block. One series has as many volumes as there are slices.

For a detailed description have a look at T1823

TODO:

  • Try to find a way how to reformat these series
  • Interpolation with ITK?
  • After a concrete plan write a change request for this bug
  • Write a test which checks the new behavior

Event Timeline

Please sketch the plan here: http://mitk.org/wiki/ChangeRequests/11106

T1823 is internal and does NOT describe the intended solution

I wrote the plan myself, please see change request

I started work on this feature in branch bug-11106-accept-gantry-tilt.

So far I did some refactoring for AnalyzeFileForITKImageSeriesReaderSpacingAssumption and changed the implementation so that

  • gantry tilt is accepted for a slice block, given that the tilt is constant
    • this is required, otherwise we would still end up with single slices
  • before loading by ITK, gantry tilt is now detected
    • this is required if we want to fix the constructed image, otherwise we don't know if and how much we need to correct

I agree with the proposed solution. Just one idea for the background value: should we use the minimal value for the specific modality (if possible) instead of the minimal value of the (C++) pixel type? Would that make sense?

(In reply to comment #4)

I agree with the proposed solution. Just one idea for the background value:
should we use the minimal value for the specific modality (if possible)
instead of the minimal value of the (C++) pixel type? Would that make sense?

Good idea if there is such a value. I'll try to find out about that, but I'm sceptical (probably good assumptions possible for CT but not for MR/PT?).

I now implemented all the calculations to understand and correct a shearing factor by means of a simple itk::ResampleImageFilter using a sheared transform.

Remains to do:

  • adapt test case
  • test with realistic data
  • enhance with more test cases

Finally got the tranformations for tilt correction right, corrected the z spacing, documented the correctin.

Still TODO (must):

  • sort out more-than-tilted images (theoretical construct but may appear and break our logic), images that are sheard in two dimensions
  • handle series with just a single slice but multiple timesteps
  • calculate size of corrected image (now slices are "shifted outside the image"
  • analyze tilt properties for 3D+t sorting
  • expand test cases

TODO (nice-to-have)

  • refactor protected header items into second header (private impl pointer) for less dependencies

(In reply to comment #7)

Finally got the tranformations for tilt correction right, corrected the z
spacing, documented the correctin.

Still TODO (must):

  • sort out more-than-tilted images (theoretical construct but may appear and break our logic), images that are sheard in two dimensions
  • handle series with just a single slice but multiple timesteps
  • calculate size of corrected image (now slices are "shifted outside the

image"

  • analyze tilt properties for 3D+t sorting

Done now.

Still TODO (must):

  • expand test cases

Basic test with constructed data is adapted, but realistic data must follow.

Also fixed test mitkDICOMTestingSanityTest with spacing-ok-sc-no2032.dcm. This was broken because in this case nothing would be loaded and the loading code would still access the first slice filename (which is not present -> segfault)

Just compared the "load each slice" against the new tilt correction, and obviously I still need to understand the transformation parameters better :-(

correct-left-corrected-right.png (1×3 px, 761 KB)

Got this whole feature working now. However, it seems I introduced some sort of error because now around four of the DICOM loading fail sometimes (when executing them repeatedly they will sometimes fail, sometimes pass). I'll have to look into that.

Fixed the error, thanks to valgrind. I just forgot to initialize two variables who would not be used for NORMAL series but were always initialized for tilted series.

(In reply to comment #4)

I agree with the proposed solution. Just one idea for the background value:
should we use the minimal value for the specific modality (if possible)
instead of the minimal value of the (C++) pixel type? Would that make sense?

I guess you forgot to set the flag then, I'll do it myself

[66fb3e]: Merge branch 'bug-11106-accept-gantry-tilt'

Merged commits:

2012-06-22 08:48:12 Daniel Maleike [b839ef]
Update MITK-Data pointer


2012-06-21 18:16:15 Daniel Maleike [7b9a19]
Rename DICOMTesting.dox; add new test case


2012-06-21 14:26:17 Daniel Maleike [1746cf]
Fix wrong comment


2012-06-21 12:56:44 Daniel Maleike [900e6f]
Initialize variables!


2012-06-21 12:30:04 Daniel Maleike [a27130]
Deactivate debug output again


2012-06-21 12:29:33 Daniel Maleike [bea6ef]
Adding a realistic test case for gantry tilt images


2012-06-21 10:51:12 Daniel Maleike [01928d]
Revert "Loading code which loads series every other time with and without tilt correction"

Previous commit stays in history for testing purposes.

This reverts commit f6355bcc32e05b9a249db201ad3c66d80dfe87b7.


2012-06-21 10:50:59 Daniel Maleike [f6355b]
Loading code which loads series every other time with and without tilt correction


2012-06-21 10:50:18 Daniel Maleike [175024]
Finally the working but not too well understood solution, including chocolate offer


2012-06-19 16:41:22 Daniel Maleike [f60e85]
Check file list size before accessing front()


2012-06-19 16:21:07 Daniel Maleike [256a4f]
Use more appropriate variable names


2012-06-19 15:36:32 Daniel Maleike [055dd7]
Add calling option to disable tilt correction on request (default=correct)


2012-06-19 15:20:50 Daniel Maleike [7c8bd4]
Adjust output size to shearing effect


2012-06-19 14:52:29 Daniel Maleike [c0d077]
Remove comment on non-problem


2012-06-19 14:52:03 Daniel Maleike [c7e333]
Comment on 3D+t problem solution


2012-06-19 14:51:49 Daniel Maleike [9f053b]
Handle single-slice-multiple-timessteps, handle sheard-but-not-tilted


2012-06-19 14:28:37 Daniel Maleike [e7dfa2]
Handle sheared-but-not-only-tilted images (still load single slices)


2012-06-19 14:16:11 Daniel Maleike [d8d80c]
Document new feature


2012-06-19 13:23:22 Daniel Maleike [9a4a55]
Set actual spacing from calculated slice distance


2012-06-19 11:52:38 Daniel Maleike [6e068c]
Calculate correction from first and last slice to minimize rounding errors


2012-06-19 11:46:56 Daniel Maleike [5c6d49]
Apply shearing IN IMAGE COORDINATES


2012-06-18 16:28:23 Daniel Maleike [9fa71d]
Calulate and apply the shearing factor, remove TODOs


2012-06-18 15:04:18 Daniel Maleike [49d88a]
Apply gantry correction and communicate all the necessary info


2012-06-16 15:29:49 Daniel Maleike [33ae6e]
Setup basic resampling pipeline if needed


2012-06-15 17:37:54 Daniel Maleike [d1472f]
Refactor AnalyzeFileForITKImageSeriesReaderSpacingAssumption, detect and accept gantry tilt


2012-06-15 13:22:41 Daniel Maleike [b55a0e]
Some notes on gantry tilt; move block analysis result into class

[e3b12a]: Merge branch 'bug-11106-accept-gantry-tilt'

Merged commits:

2012-06-22 11:16:09 Daniel Maleike [589c36]
COMP: Shorten hash to match manually constructed file on mbits, hopefully

[e2985d]: Merge branch 'bug-11106-accept-gantry-tilt'

Merged commits:

2012-06-22 11:47:40 Daniel Maleike [3112b7]
COMP: Update test data

I just a missing part: with positive tilt angles we need to compensate the shift by padding pixels "on the other side" of the image block, i.e. before origin. This is done in Branch bug-11106-complete-gantry-tilt.

And I just got more realistic data, which seems to contain multiple acquisisions within one SeriesInstanceUID. The sorter constructs a visuallz unusual grouping. It seems that we miss a check if the calculated tilt is approximately the one documented in the DICOM tag "gantry tilt". We should make this shure to get better results. Images as soon as I figured out if my idea helps.

[7151b2]: Merge branch 'bug-11106-accept-gantry-tilt'

Merged commits:

2012-07-04 13:00:57 Marco Nolden [905ff2]
Compilation fix for gcc 4.1.2

Contrib by Matt Clarkson

Explaining the long pause: there is still an obvious error in at least one case (see attachment). Until I understand this issue, the feature is not yet done.

Screenshot from 2012-07-04 18:41:15.png (566×684 px, 49 KB)

I guess now I got it right. What I did wrong so far:

  • due to my far distance from school, I messed up tanh() and atan(), so some angles where miscalculated
  • I forgot to incorporate the spacing miscalculation made by ITK's reader into my shear factor calculation
  • I forgot to calculate the sign of the shear factor
  • I probably tested using wrong data

With the most recent branch "bug-11106-gantry-tilt-cleaned-up" I tested the following on several images:

  • once load a series without tilt correction (lots of single slices)
  • once load it with correction
  • overlay the results in an image fusion way (as in attachment "Obvious TODO"))

Now I cannot even see tiny differences in the transversal plane, so I assume the calculations are all right now.

What still needs to be checked: I have one dataset from a hospital, which does NOT load 100% correctly. Instead I can see tiny shift errors (around max. 1mm) in the transversal plane. However, other data from this hospital works 100% fine. I guess I picked a dataset where the IT person of that hospital tried to correct "something" in the data, because 1. the header says "Manufacturer: DCMTK" (instead of Siemens) and 2. a colleague told me that "there was some kind of experiment done by this guy". We'll check with him and make sure that real data loads correctly.

(In reply to comment #21)

What still needs to be checked: I have one dataset from a hospital, which
does NOT load 100% correctly. Instead I can see tiny shift errors

This issue still remains. all but this series from that hospital loads 100% fine, but be still need to figure out what is wrong with our code in this special case.

(In reply to comment #23)

  • Try to find a way how to reformat these series
  • Interpolation with ITK?

For the first part, we now are certain, that our correction code is correct and applies a shear transform that matches the gantry tilt well.

The visual effect seems to come from a rendering issue: two images which are slightly shifted against each other are forced into the same visual pixel grid. Before filing a bug, I'll check if this behavior still exists with the current master branch, because my work is based on an old version by now.

Regarding testing, this will be done next

[f3d56c]: Merge branch 'bug-11106-gantry-tilt-cleaned-up'

Merged commits:

2012-08-21 13:31:38 Daniel Maleike [357096]
Add an illustration to the tilt correction code


2012-08-21 13:31:26 Daniel Maleike [f07c26]
Move testing documentation where it can be found by Doxygen


2012-08-21 09:53:20 Daniel Maleike [562052]
Document and clean debug messages


2012-08-20 10:41:06 Daniel Maleike [ed4199]
Improved tilt correction (see comments below)

  • correctly calculate the shear factor
    • was something else before
  • correctly calculate index-to-world transform of image
    • ignored image spacing before
  • correctly combine shear factor with image spacing

2012-07-07 17:18:27 Daniel Maleike [487fa5]
Move typedefs to class


2012-07-07 17:18:18 Daniel Maleike [ca40dd]
Document all those else cases


2012-07-07 17:17:43 Daniel Maleike [50ccf0]
Remove obsolete code


2012-07-07 17:09:50 Daniel Maleike [69e8fc]
Update comment


2012-06-26 09:47:22 Daniel Maleike [73ab0e]
Fix tilt comensation: get direction right, get shear right

[43310e]: Merge branch 'bug-11106-gantry-tilt-cleaned-up'

Merged commits:

2012-08-21 14:25:28 Daniel Maleike [cc075d]
Update link to MITK-Data

Conflicts:

CMakeExternals/MITKData.cmake


2012-08-21 13:31:38 Daniel Maleike [357096]
Add an illustration to the tilt correction code


2012-08-21 13:31:26 Daniel Maleike [f07c26]
Move testing documentation where it can be found by Doxygen


2012-08-21 09:53:20 Daniel Maleike [562052]
Document and clean debug messages


2012-08-20 10:41:06 Daniel Maleike [ed4199]
Improved tilt correction (see comments below)

  • correctly calculate the shear factor
    • was something else before
  • correctly calculate index-to-world transform of image
    • ignored image spacing before
  • correctly combine shear factor with image spacing

2012-07-07 17:18:27 Daniel Maleike [487fa5]
Move typedefs to class


2012-07-07 17:18:18 Daniel Maleike [ca40dd]
Document all those else cases


2012-07-07 17:17:43 Daniel Maleike [50ccf0]
Remove obsolete code


2012-07-07 17:09:50 Daniel Maleike [69e8fc]
Update comment


2012-06-26 09:47:22 Daniel Maleike [73ab0e]
Fix tilt comensation: get direction right, get shear right

[95791e]: Merge branch 'bug-11106-gantry-tilt-cleaned-up'

Merged commits:

2012-08-21 16:12:36 Daniel Maleike [faca3e]
COMP: fix typo

Daniel and I finished the work on this feature and added additional tests to the DICOMLoading Tests.

Since the last update in this ticket additional documentation and code clean up was done. Additional changes to the code:

  • Improved tilt correction:
    • correctly calculate the shear factor
      • was something else before
    • correctly calculate index-to-world transform of image
      • ignored image spacing before
    • correctly combine shear factor with image spacing
    • correctly compute corrected additionalsize
      • before cast to int was wrong

Added tests:
We used the DICOMLoading Test mechanism of MITK. Therefore we added a new folder TiltedData in the MITK-Data repository. The test data has tilted data from a real life case and a synthethic test case. All data was compressed and anonymized.

Additional information for the test data can be found in the file description.txt in the MITK-Data\TiltedData folder.

[620cdc]: Merge branch 'bug-11106-gantry-tilt-cleaned-up'

Merged commits:

2012-08-27 14:17:58 Johannes Kast [b88875]
changed mitk data revision for new tilted test data


2012-08-27 10:28:40 Johannes Kast [8af79e]
added new ct_tilt dir to the tests; renamed head tilt dir


2012-08-27 10:27:50 Johannes Kast [995665]
corrected wrong additional size computation