# SimpleITK cast 4D image

**URL:** <https://discourse.itk.org/t/simpleitk-cast-4d-image/3638>\
**Category:** Algorithms\
**Tags:** simpleitk\
**Created:** [November 19, 2020, 8:21pm UTC](https://discourse.itk.org/t/simpleitk-cast-4d-image/3638 "2020-11-19T20:21:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasteuwen](https://discourse.itk.org/user_avatar/discourse.itk.org/jonasteuwen/32/1335_2.png) [@jonasteuwen](https://discourse.itk.org/u/jonasteuwen)\
**Post date:** [November 19, 2020, 8:21pm UTC](https://discourse.itk.org/t/simpleitk-cast-4d-image/3638/1 "2020-11-19T20:21:50Z")

</div>

The question is inspired by this reply: [Weighted average over temporal dimension](https://discourse.itk.org/t/weighted-average-over-temporal-dimension/3636/5)

Shortly: I have an external intercept parameter -1024 and a SimpleITK image (4D) with an unsigned data type of which I want to subtract 1024. Since casting of 4D is not supported in SimpleITK, what would we the best way to go about this keeping my spacing, origin and direction, and others intact?  
In ITK perhaps `SliceBySliceImageFilter` might be an option (?) but it is not supported in SimpleITK.

---

<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:** [November 19, 2020, 8:32pm UTC](https://discourse.itk.org/t/simpleitk-cast-4d-image/3638/2 "2020-11-19T20:32:23Z")

</div>

> [@jonasteuwen](#):
>
> ve an external intercept paramete

Please look at this example with a python function decorator called `slice_by_slice`: [Slice by Slice Adaptive Histogram Equalization — SimpleITK 2.0rc2 documentation](https://simpleitk.readthedocs.io/en/master/link_SliceBySliceDecorator_docs.html)

You can use it like this:

```auto
@slice_by_slice
def do_3d_image_stuff(img):
     return sitk.Cast(img, sitk.sitkFloat32)

```
