# ITK Affine transform doesn't translate the image as expected

**URL:** <https://discourse.itk.org/t/itk-affine-transform-doesnt-translate-the-image-as-expected/6584>\
**Category:** Beginner Questions\
**Tags:** itk, dicom, cpp\
**Created:** [April 18, 2024, 5:45am UTC](https://discourse.itk.org/t/itk-affine-transform-doesnt-translate-the-image-as-expected/6584 "2024-04-18T05:45:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erezke](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/82dd89/32.png) [@Erezke](https://discourse.itk.org/u/Erezke)\
**Post date:** [April 18, 2024, 5:45am UTC](https://discourse.itk.org/t/itk-affine-transform-doesnt-translate-the-image-as-expected/6584/1 "2024-04-18T05:45:40Z")

</div>

Hi

I am trying to translate a DICOM image using an affine transform to a new position, but when I compare the centers of both images (before/after) it seems like the image did not move. Following is the code I use:

```
...
auto shearedImage = shearResampler->GetOutput();	
			
ImageType::PointType newVolumeCenter;
shearedImage->TransformContinuousIndexToPhysicalPoint(indx, newVolumeCenter);

// volumeCenter is the oroginal volume's cener
// newVolumeCenter is the canter after I manipulated the original volume
const auto diffCenter = volumeCenter - newVolumeCenter;

itk::AffineTransform<double, 3>::Pointer transformTranslate = itk::AffineTransform<double, 3>::New();
transformTranslate->SetCenter(volumeCenter);
transformTranslate->Translate(diffCenter);

itk::ResampleImageFilter<ImageType, ImageType>::Pointer translateResampler = 
itk::ResampleImageFilter<ImageType, ImageType>::New();
translateResampler->SetInput(shearedImage);
translateResampler->SetDefaultPixelValue(-1000.0);
translateResampler->SetSize(size);
translateResampler->SetOutputOrigin(origin);
translateResampler->SetOutputSpacing(spacing);
translateResampler->SetOutputDirection(direction);
translateResampler->SetTransform(transformTranslate);
shearResampler->SetInterpolator(itk::LinearInterpolateImageFunction<ImageType>::New());
translateResampler->Update();

auto translatedImage = translateResampler->GetOutput();			

```

What am I doing wrong?  
Thank you
