[Insight-users] transform inverse?
Hegenbart, Lars
Lars.Hegenbart at hs.fzk.de
Mon Oct 6 10:39:50 EDT 2008
Dear ITK-community,
I am defining an affine transform with [2, 0, 0, 0, 2, 0, 0, 0, 2,
0, 0, 0], basically a stretch of factor 2 in all 3 dimensions. I want to
apply it to an input image to create an output image with same
parameters (spacing, etc.). I end up getting an output which is scaled
by a factor of 0.5 instead of 2. If I choose 0.5 in the diagonal of the
matrix of the affine transform, I end up with the wanted result.
It seems somehow to be inverted. What's wrong or is that normal?
Thanks for any hints.
Best regards
Lars
PS: here some relevant code parts:
typedef itk::Image< unsigned char, Dimension > InputImageType;
typedef itk::Image< unsigned char, Dimension > OutputImageType;
InputImageType::Pointer i_image;
OutputImageType::Pointer o_image;
InputImageType::SpacingType spacing;
spacing[0] = 6; //spacing along x
spacing[1] = 6; //spacing along y
spacing[2] = 6; //spacing along z
i_image->SetSpacing(spacing);
InputImageType::PointType origin;
origin[0] = 0;
origin[1] = 0;
origin[2] = 0;
i_image->SetOrigin(origin);
InputImageType::SizeType size;
size[0] = 100; // size along x
size[1] = 100; // size along y
size[2] = 100; // size along z
typedef itk::AffineTransform< double, Dimension >
TransformType;
TransformType::Pointer transform;
typedef TransformType::ParametersType ParametersType;
const unsigned int numberOfParameters = transform-
>GetNumberOfParameters();
ParametersType parameters( numberOfParameters );
parameters_affine[ 0]= 2;
parameters_affine[ 1]= 0;
parameters_affine[ 2]= 0;
parameters_affine[ 3]= 0;
parameters_affine[ 4]= 2;
parameters_affine[ 5]= 0;
parameters_affine[ 6]= 0;
parameters_affine[ 7]= 0;
parameters_affine[ 8]= 2;
parameters_affine[ 9]= 0;
parameters_affine[10]= 0;
parameters_affine[11]= 0;
transform->SetParameters( parameters);
typedef itk::ResampleImageFilter< InputImageType,
OutputImageType >
FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetTransform(transform);
typedef itk::NearestNeighborInterpolateImageFunction<
InputImageType, double > InterpolatorType;
InterpolatorType::Pointer interpolator =
InterpolatorType::New();
filter->SetInterpolator(interpolator);
filter->SetDefaultPixelValue(0);
filter->SetOutputSpacing(i_image->GetSpacing()); // same spacing
like InputImage
filter->SetOutputOrigin(i_image->GetOrigin()); // same like
InputImage
filter->SetSize(size); // same like InputImage
filter->SetInput(i_image);
o_image = filter->GetOutput();
More information about the Insight-users
mailing list