# Output MRI images have value 0 (almost) everywhere after resampling using SimpleITK

**URL:** <https://discourse.itk.org/t/output-mri-images-have-value-0-almost-everywhere-after-resampling-using-simpleitk/5912>\
**Category:** Algorithms\
**Tags:** simpleitk, registration, python\
**Created:** [April 30, 2023, 9:30pm UTC](https://discourse.itk.org/t/output-mri-images-have-value-0-almost-everywhere-after-resampling-using-simpleitk/5912 "2023-04-30T21:30:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluefire](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@bluefire](https://discourse.itk.org/u/bluefire)\
**Post date:** [April 30, 2023, 9:30pm UTC](https://discourse.itk.org/t/output-mri-images-have-value-0-almost-everywhere-after-resampling-using-simpleitk/5912/1 "2023-04-30T21:30:25Z")

</div>

Hey!

I have 3-dimensional NIfTI MRI images that I would like to resample to uniform voxel size (1, 1, 1). This works fine:

```auto
img = sitk.ReadImage(img_path)

output_spacing = [1.0, 1.0, 1.0]

input_spacing = img.GetSpacing()
input_size = img.GetSize()
size_x = int(round(input_size[0] * input_spacing[0]/output_spacing[0]))
size_y = int(round(input_size[1] * input_spacing[1]/output_spacing[1]))
size_z = int(round(input_size[2] * input_spacing[2]/output_spacing[2]))
size = [size_x, size_y, size_z]

resampler = sitk.ResampleImageFilter()

resampler.SetDefaultPixelValue(0)
resampler.SetOutputDirection(img.GetDirection())
resampler.SetInterpolator(sitk.sitkLinear)
resampler.SetOutputOrigin(img.GetOrigin())
resampler.SetOutputSpacing([1.0, 1.0, 1.0])
resampler.SetSize(size)

img_resampled = resampler.Execute(img)

```

However, the original images also look rotated:  
 ![232944](https://discourse.itk.org/uploads/default/original/2X/5/51da2f1f92587263ad232e8eef47e9c56ac9a8b7.png)

I suspect this is because they have strange directions, e.g. `(-0.08117500577885353, -0.01032194044222358, 0. 9966465738475954, 0.9617029292569339, 0.26183942332790555, 0.08103908870110368, 0.26179781186143564, -0.9650562542861514, 0.011325764448564252)`.

But if I set `resampler.SetOutputDirection([1.0, 0.0, 0.0, 1.0, 0.0, 1.0])` instead of `resampler.SetOutputOrigin(img.GetOrigin()`), the output MRT images have (almost) everywhere the value 0.

What is the reason and how can I fix this error?

Thanks in advance for any help!

---

<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 30, 2023, 11:36pm UTC](https://discourse.itk.org/t/output-mri-images-have-value-0-almost-everywhere-after-resampling-using-simpleitk/5912/2 "2023-04-30T23:36:37Z")

</div>

Hello @bluefire,

Please see [this Jupyer notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/05_Results_Visualization.ipynb), the `make_isotropic` function, You might find the toolkit’s [notebooks repository](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/) of interest too.

---

<div class="post-metadata">

**Author:** ![bluefire](https://discourse.itk.org/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@bluefire](https://discourse.itk.org/u/bluefire)\
**Post date:** [May 2, 2023, 7:40am UTC](https://discourse.itk.org/t/output-mri-images-have-value-0-almost-everywhere-after-resampling-using-simpleitk/5912/3 "2023-05-02T07:40:28Z")

</div>

Thanks for your help! I will try it!
