# How to set center z if the 3D image is rotated along z axis with ITK::affineTransform?

Hello all,
I am working on 3D image rotation now. And ITK is really a great tool to do image processing. I have used affinetransform to rotate the 3D image. The rotation is done along z axis, in my view, the center on z is no matter with the rotation result. center.z can be any value, and the results are same. Is it Right?
But when I run the code below, I found if the center z changed the 3D image rotated result is not same.

``````	 using MatrixType = <double,3, 3>;
MatrixType matrix;
matrix[0][0] = sqrt(2)/2;
matrix[0][1] = sqrt(2)/2;
matrix[0][2] = 0.;

matrix[1][0] = -matrix[0][1];
matrix[1][1] = matrix[0][0];
matrix[1][2] = 0.;

matrix[2][0] = 0.;
matrix[2][1] = 0.;
matrix[2][2] = 1.;

using ImageType = itk::Image<float, 3>;
using AffineTransformType = itk::AffineTransform<double, 3>;
AffineTransformType::Pointer transform = AffineTransformType::New();
ImageType::PointType centerPoint;
centerPoint[0] = origin1[0] + 0.5 * (size[0] - 1) * spacing[0];
centerPoint[1] = origin1[1] + 0.5 * (size[1] - 1) * spacing[1];
centerPoint[2] = origin1[2] + 0.5 * (size[2] - 1) * spacing[2];
//ITK::TransformContinuousIndexToPhysicalPoint can also work.
transform->SetCenter(centerPoint);
transform->SetMatrix(matrix);

using ResampleFilterType = itk::ResampleImageFilter<ImageType, ImageType>;
ResampleFilterType::Pointer resampleFilter = ResampleFilterType::New();
// Set the input image
resampleFilter->SetInput(OriImage1);
// Set the transform
resampleFilter->SetTransform(transform);

ImageType::SizeType outputSize;
outputSize[0] = m_nWid;
outputSize[1] = m_nHei;
outputSize[2] = m_nSliceNum;
resampleFilter->SetSize(outputSize);
ImageType::SpacingType outputSpacing;
outputSpacing[0] = spacing[0];
outputSpacing[1] = spacing[1];
outputSpacing[2] = spacing[2];
resampleFilter->SetOutputSpacing(outputSpacing);
ImageType::PointType outputOrigin;

typedef itk::LinearInterpolateImageFunction<ImageType> InterpolatorType;
InterpolatorType::Pointer interpolator = InterpolatorType::New();

resampleFilter->SetInterpolator(interpolator);// Set the desired interpolation method
resampleFilter->Update();
ImageType::Pointer outputImage = resampleFilter->GetOutput();
``````

The rotation result is right on some axial images. But some slice images are missed.
Here is the result, we can see some images are missed in sagittal. Some missed images are black.
Some missed images are half black. Why there is change in z axis? In the rotation matrix, there should not be changed in z axis.