[ITK] [ITK-users] Rotation of anisotropic 3D image

Francois Budin francois.budin at kitware.com
Tue Sep 12 08:55:03 EDT 2017


Hello Antoine,

What you are doing is correct. What I would do is that I would use the
smallest value of the spacing and create an isotropic output image (similar
to what you are doing with setting your output spacing to {0.1,0.1,0.1},
but in an automatic manner.
The only reason I can think of why you are getting an enterely black output
image is maybe because your output image space does not cover your
transformed image. If you decrease the spacing, you also need to adjust the
image size to make sure that your transformed image will be contained in
the output image space.
I created a project a long time ago that computes the output image space
based on an input image and a transform [1]. Maybe looking at that project
will help you.

Hope this helps,
Francois

[1]
https://github.com/fbudin69500/ITKTransformTools/blob/master/GetNewSizeAndOrigin.cxx

On Tue, Sep 12, 2017 at 5:41 AM, g2 <antoine.letouzey at gmail.com> wrote:

> Hi all,
>
> I am trying to rotate in 3D with a arbitrary rotation matrix a 3D image
> with
> non uniform spacing (0.15, 0.15, 0.19). I am currently using
> itk::AffineTransform because at some point in the future I would like to
> introduce a translation. My question is about the spacing of the output
> image. Since my rotation matrix can be anything, I cannot just re-use the
> spacing of my original image. I actually do not care to much about the
> output spacing, it can be the same, it can be isotropic, whatever as long
> as
> the data makes sense.
>
> here is a bit of code of what I've done so far:
>
> typedef itk::Image<short, 3> Image3d;
> Image3d::Pointer itkImage = getImageSomehow();
> typedef itk::AffineTransform<double, 3> TransformType;
> TransformType::Pointer Rt = TransformType::New();
> TransformType::ParametersType params(12);
> for (int i = 0; i < 9; i++){
>         params[i] = R[i/3][i%3]; // R is the rotation matrix of type
> double[3][3]
> }
> params[9] = 0;
> params[10] = 0;
> params[11] = 0;
>
> Rt->SetParameters(params);
>
> typedef itk::ResampleImageFilter<Image3d, Image3d > FilterType;
> FilterType::Pointer filter = FilterType::New();
> typedef itk::NearestNeighborInterpolateImageFunction<Image3d, double >
> InterpolatorType;
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> filter->SetInterpolator(interpolator);
> filter->SetDefaultPixelValue(255);
> filter->SetOutputOrigin(itkImage->GetOrigin());
> filter->SetOutputSpacing(itkImage->GetSpacing());
> //double outSpacing[3] = { 0.1, 0.1, 0.1 };
> //filter->SetOutputSpacing(outSpacing);
> filter->SetSize(itkImage->GetLargestPossibleRegion().GetSize());
> filter->SetOutputDirection(itkImage->GetDirection());
> filter->SetInput(itkImage);
> filter->SetTransform(Rt);
> filter->Update();
>
>
> After this when I save filter->GetOutput() and open it with IKT-Snap I can
> see my new image properly rotated. But it has the same spacing as the input
> image, as specified with filter->SetOutputSpacing(itkImage->GetSpacing());
> and to me this doesn't make sense. The axes are rotated and so should be
> the
> spacing. When I try to put some other values, such as (0.1, 0.1, 0.1). The
> output image is all black. I'm confused because to me those values are not
> more erroneous than a plain copy of the input spacing.
>
> Questions :
> I want to rotate a generic 3D image with anisotropic spacing with a generic
> rotation matrix (i.e. not around a single axis and not with a n*90° angle)
> so that any physical point P in the original volumes maps to R*P in the
> final one. How should I proceed ?
>
> thanks
>
>
>
> --
> Sent from: http://itk-insight-users.2283740.n2.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.php
>
> 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://public.kitware.com/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20170912/8b11eada/attachment-0001.html>
-------------- next part --------------
_____________________________________
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.php

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://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list