[Insight-users] itk ResampleImageFilter + OutputDirection Problem (dicom)
Luis Ibanez
luis.ibanez at kitware.com
Tue Mar 16 13:43:30 EDT 2010
Hi Sebastien,
Thanks for your detailed information.
However, I couldn't find in your email the
information about how you are initializing
the Affine Transform.
Given that you are resampling an image
into the image grid of the *same* image,
the most likely cause of the problem is
that your initialization of the Affine Transform
is incorrect.
A common mistake is to forget to set the
center of rotation of the Transform.
When users forget this setting, the Affine
transform performs rotations (and scaling)
using the origin of coordinates (0,0,0) as
the center of rotation.
In the particular case of your images, this
center of rotation is quite far from the image.
( given that the origin is located at
Origin: [-110.5, -78.3063, -72.7575] )
Please post to the list the code that you
are using to initialize the Affine transform
and the parameters of the transform.
FYI: A typical initialization of the Affine transform
will setup the center of rotation to the coordinates
of the physical coordinates of the pixes located in
the middle of the image.
All this is explained in detail in the
ITK Software Guide
http://ww.itk.org/ItkSoftwareGuide.pdf
in Section 6.9.4. "Resample Image Filter"
in pdf-pages 254-274.
Rotation is described in pdf-page 272.
At the top of the page you will see a recommended
method for setting the center of rotation.
Regards,
Luis
-------------------------------------------------------------
On Mon, Mar 8, 2010 at 4:56 AM, Aussensaiter <s.ganger at hotmail.com> wrote:
>
>
> Luis Ibanez wrote:
>>
>> Hi Sebastian
>>
>>
>> Thanks for your detailed description of the problem.
>>
>>
>> 1) If you are using the latest release of ITK, you
>> don't need to use the itk::OrientedImage anymore.
>> The standard itk::Image now behaves the same
>> as the itk::OrientedImage.
>>
>>
>> 2) In order to interpret the correctness of the resampling,
>> we need you to tell us what parameters did you set up
>> in the Affine transform.
>>
>> Please post to the mailing list the Affine transform
>> parameters that you used.
>>
>>
>> 3) Before you called the method:
>>
>> SetOutputDirection(itkimage->GetDirection())
>>
>> did you make sure the the "itkimage" was read in memory ?
>>
>> For example, if "itkimage" is the output of a reader,
>> please make sure that you call "Update()" in that
>> reader, before you call the SetOutputDirection()
>> line shown above.
>>
>>
>> 4) To help you beyond this, we will need you to tell us:
>>
>> A) Parameters of the input image:
>>
>> Origin
>> Spacing
>> Direction cosines
>>
>> B) Parameters that you set in the resampling filter
>>
>> OutputOrigin
>> OutputSpacing
>>
>> C) How did you initialized the AffineTransform
>>
>>
>>
>> For a detailed description of how the ResampleImageFilter
>> works, you should read the ITK Software Guide:
>>
>> http://www.itk.org/ItkSoftwareGuide.pdf
>>
>> In particular,
>>
>> "Section 6.9.4 Resample Image Filter"
>>
>> In pdf-pages 254-252
>>
>>
>> The source code of the examples described in
>> this section are available in:
>>
>>
>> Insight/Examples/Filtering
>> ResampleImageFilter.cxx
>> ResampleImageFilter2.cxx
>> ResampleImageFilter3.cxx
>> ResampleImageFilter4.cxx
>> ResampleImageFilter5.cxx
>> ResampleImageFilter6.cxx
>> ResampleImageFilter7.cxx
>> ResampleImageFilter8.cxx
>> ResampleImageFilter9.cxx
>> ResampleOrientedImageFilter.cxx
>> ResampleVolumesToBeIsotropic.cxx
>>
>>
>>
>>
>> Regards,
>>
>>
>> Luis
>>
>>
>> -----------------------------------------------------------------------------------
>> On Wed, Mar 3, 2010 at 8:52 AM, Aussensaiter <s.ganger at hotmail.com> wrote:
>>>
>>> Hi.
>>> Im using the latest Release of VTK/ITK/GDCM and currently I am working on
>>> viewing slices in 3 dimension from a set of dicom slices. I stumbled
>>> across
>>> a problem and i can't figure out how to solve it, likely because i don't
>>> fully understand what the transform/ResampleImageFilter does.
>>>
>>> I have a itkOrientedImage that is created from slices, which results in
>>> a
>>> 3D image.
>>> I then pass it to an ResampleImageFilter where i use LinearInterpolation
>>> and
>>> AffineTransform. So far so good, _but_ if I got 1 dataset that produces
>>> problems:
>>> http://pubimage.hcuge.ch:8080/ The set(one of them, afterwards i
>>> found 2
>>> more) that makes problems is the "KNEE" example.
>>>
>>> I got two cases and two sets, for an example that works heres the "brain"
>>> set:
>>> http://www.mathworks.com/matlabcentral/fileexchange/2762-dicom-example-files
>>>
>>> Case 1:
>>> I _don't_ use the method "SetOutputDirection(itkimage->GetDirection())"
>>> and
>>> don't feed the filter with the direction from the image.
>>> The brain image is shown exactly as in Slicer3 which i use to compare my
>>> results, and isn't a cube with horizontal lines.
>>> The images are not taken horizontally, so its a little bit rotated, which
>>> can be seen in this image :
>>> http://old.nabble.com/file/p27768466/Bildschirmphoto1.png
>>> But, the knee image is just a monocoloured canvas with no texture at all,
>>> just blank and one colour, so basically useless.
>>>
>>> Case2:
>>> I _use_ the method "SetOutputDirection(itkimage->GetDirection())" and
>>> feed
>>> the filter with the direction from the image.
>>> Then i get both sample sets correct, but in the brain example the little
>>> rotation is missing. And also in the Knee example of course, but that is
>>> the
>>> only way I can view it anyway.
>>>
>>> Can someone tell me how to get around this, and how to fix it ? I don't
>>> know
>>> if I am using the wrong transform, or how to tell the transform how to
>>> translate the dimensions ?
>>>
>>> Thanks, and seeing forward to your help :)
>>> --
>>> View this message in context:
>>> http://old.nabble.com/itk-ResampleImageFilter-%2B-OutputDirection-Problem-%28dicom%29-tp27768466p27768466.html
>>> Sent from the ITK - Users mailing list archive at Nabble.com.
>>>
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>>
> At first, thank you. I have look into the documentation and the
> resampleimagefilter examples, but there are just a few examples for
> 3D-Resample. So, step by step answers to your questions:
>
> 1, I tried that before, it doesn't have any effect so I sticked to
> orientedimage till i got the problem solved.
> 2, I gonna attach the code here
> 3, Yes, update of the image was called, and the orientation at least in my
> opinion seemed to be right
> 4, See #2. And im gonna post the last lines of the
> itkimage->Print(std::cout) after and before the resample.
>
> So, here's a minimal example of the code:
> itkimage1 = reader1->GetOutput();
> itkimage1->Update();
>
> typedef itk::AffineTransform<double> TransformType;
> TransformType::Pointer transform = TransformType::New();
>
> typedef itk::LinearInterpolateImageFunction<ImageType, double>
> InterpolateType;
> InterpolateType::Pointer interpolator = InterpolateType::New();
> filter1->SetInput(reader1->GetOutput());
> filter1->SetInterpolator(interpolator);
> filter1->SetDefaultPixelValue(0);
>
> filter1->SetOutputOrigin(itkimage1->GetOrigin());
> filter1->SetOutputSpacing(itkimage1->GetSpacing());
>
> //This (SetOutputDir) produces the mistake
> //if enabled, just a cubic image is created
> //if disabled, some images are oriented right, while others just
> show a blank canvas
> filter1->SetOutputDirection(itkimage1->GetDirection());
>
>
> filter1->SetOutputStartIndex(itkimage1->GetLargestPossibleRegion().GetIndex());
> ImageType::RegionType inputRegion =
> itkimage1->GetLargestPossibleRegion();
> ImageType::SizeType size = inputRegion.GetSize();
> filter1->SetSize(inputRegion.GetSize());
>
> filter1->UpdateLargestPossibleRegion();
>
> filter1->SetTransform( transform );
> filter1->Update();
> itkimage1 = filter1->GetOutput();
> itkimage1->Update();
> itkimage1->Print(std::cout);
>
> Here are the orientations and dimensions
> brain before resample:
>
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [256, 256, 20]
> Spacing: [0.859375, 0.859375, 7.07107]
> Origin: [-110.5, -78.3063, -72.7575]
> Direction:
> 1 0 0
> 0 0.99096 -0.134158
> 0 0.134158 0.99096
>
> IndexToPointMatrix:
> 0.859375 0 0
> 0 0.851606 -0.94864
> 0 0.115292 7.00715
>
> PointToIndexMatrix:
> 1.16364 0 0
> 0 1.15312 0.156111
> 0 -0.0189728 0.140143
>
>
> brain after Resample with SetOutputDirection:
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [256, 256, 20]
> Spacing: [0.859375, 0.859375, 7.07107]
> Origin: [-110.5, -78.3063, -72.7575]
> Direction:
> 1 0 0
> 0 0.99096 -0.134158
> 0 0.134158 0.99096
>
> IndexToPointMatrix:
> 0.859375 0 0
> 0 0.851606 -0.94864
> 0 0.115292 7.00715
>
> PointToIndexMatrix:
> 1.16364 0 0
> 0 1.15312 0.156111
> 0 -0.0189728 0.140143
>
>
> brain after Resample with SetOutputDirection commented out(showing the right
> orientation):
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [256, 256, 20]
> Spacing: [0.859375, 0.859375, 7.07107]
> Origin: [-110.5, -78.3063, -72.7575]
> Direction:
> 1 0 0
> 0 1 0
> 0 0 1
>
> IndexToPointMatrix:
> 0.859375 0 0
> 0 0.859375 0
> 0 0 7.07107
>
> PointToIndexMatrix:
> 1.16364 0 0
> 0 1.16364 0
> 0 0 0.141421
>
>
>
>
> KNEE before resample:
>
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [560, 560, 26]
> Spacing: [0.285714, 0.285714, 3.79999]
> Origin: [149.324, -115.483, 75.9866]
> Direction:
> -0.10118 0 -0.994868
> 0.994868 0 -0.10118
> 0 -1 -0
>
> IndexToPointMatrix:
> -0.0289084 0 -3.78049
> 0.284248 0 -0.384481
> 0 -0.285714 0
>
> PointToIndexMatrix:
> -0.354128 3.48204 0
> 0 0 -3.5
> -0.261808 -0.0266263 0
>
>
>
> KNEE after Resample with SetOutputDirection(showing an output):
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [560, 560, 26]
> Spacing: [0.285714, 0.285714, 3.79999]
> Origin: [149.324, -115.483, 75.9866]
> Direction:
> -0.10118 0 -0.994868
> 0.994868 0 -0.10118
> 0 -1 -0
>
> IndexToPointMatrix:
> -0.0289084 0 -3.78049
> 0.284248 0 -0.384481
> 0 -0.285714 0
>
> PointToIndexMatrix:
> -0.354128 3.48204 0
> 0 0 -3.5
> -0.261808 -0.0266263 0
>
> KNEE after Resample with SetOutputDirection commented out(showing blank
> image):
> RequestedRegion:
> Dimension: 3
> Index: [0, 0, 0]
> Size: [560, 560, 26]
> Spacing: [0.285714, 0.285714, 3.79999]
> Origin: [149.324, -115.483, 75.9866]
> Direction:
> 1 0 0
> 0 1 0
> 0 0 1
>
> IndexToPointMatrix:
> 0.285714 0 0
> 0 0.285714 0
> 0 0 3.79999
>
> PointToIndexMatrix:
> 3.5 0 0
> 0 3.5 0
> 0 0 0.263159
>
>
>
>
> Sorry for having such an immense information here, and thanks for your help.
> :)
> --
> View this message in context: http://old.nabble.com/itk-ResampleImageFilter-%2B-OutputDirection-Problem-%28dicom%29-tp27768466p27818617.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list