[ITK-users] Rotation of anisotropic 3D image
g2
antoine.letouzey at gmail.com
Tue Sep 12 05:41:24 EDT 2017
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/
More information about the Insight-users
mailing list