# Apply 2D Affine transformation to a 3D image

**URL:** <https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899>\
**Category:** Beginner Questions\
**Tags:** simpleitk, registration\
**Created:** [April 1, 2022, 5:45pm UTC](https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899 "2022-04-01T17:45:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moha\_data](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@Moha\_data](https://discourse.itk.org/u/Moha_data)\
**Post date:** [April 1, 2022, 5:45pm UTC](https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899/1 "2022-04-01T17:45:52Z")

</div>

Hello,  
How can I apply the result of 2D affine registration to a 3D image? For now, I just consider a 3D image as a series of 2D images and apply the transformation to each of them, which is not efficient. I appreciate your thoughts on this.

Regards,

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [April 1, 2022, 5:56pm UTC](https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899/2 "2022-04-01T17:56:36Z")

</div>

Create a 3D affine transform, and set relevant parameters which you [get](https://itk.org/Doxygen/html/classitk_1_1Transform.html#aec241af88306bdcd01b1f0a7063ef08b) from 2D one. Namely, 2x2 top left matrix, and x and y translations.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [April 1, 2022, 6:11pm UTC](https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899/3 "2022-04-01T18:11:46Z")

</div>

Hello @Moha_data,

See [here](https://github.com/niaid/sitk-ibex/blob/af14add32f75c53f9f3ce577a43f0fd528fd9725/sitkibex/registration.py#L279-L295).

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [April 1, 2022, 7:05pm UTC](https://discourse.itk.org/t/apply-2d-affine-transformation-to-a-3d-image/4899/4 "2022-04-01T19:05:09Z")

</div>

If you do the resampling in 3D the interpolation will be done in 3D which may not be what you are looking for.

You could create a 2D resample filter, and utilize the [SliceBySliceImageFilter](https://itk.org/Doxygen/html/classitk_1_1SliceBySliceImageFilter.html) to perform the operation on each slice.
