# reslicing nifti(.nii) file

**URL:** <https://discourse.slicer.org/t/reslicing-nifti-nii-file/1662>\
**Category:** Support\
**Tags:** python, nifti\
**Created:** [December 14, 2017, 8:00pm UTC](https://discourse.slicer.org/t/reslicing-nifti-nii-file/1662 "2017-12-14T20:00:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaglisR](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/naglisr/32/16280_2.png) [@NaglisR](https://discourse.slicer.org/u/NaglisR)\
**Post date:** [December 14, 2017, 8:00pm UTC](https://discourse.slicer.org/t/reslicing-nifti-nii-file/1662/1 "2017-12-14T20:00:47Z")

</div>

Hey everyone,

I am working with nii files (head MRI scans) that i 1)open and save in 3D Slicer as nii.gz 2)Load the nii.gz file with python and take a certain number of slices from the 3D numpy array (for example the 10 slices from the axial view). 3)Then I construct a nii image to save using the saved original nii affine transformation data. However after saving it isn’t properly displayed if I load the resliced nii file into Slicer. The whole code basically looks like this:

```auto
image = nib.load(file_name_MRI)
original_image_affine = image.affine
image = image.get_data()
resliced = image[:,60:70,:]
resliced_nii_image = nib.Nifti1Image(resliced, original_img_affine)
nib.save(resliced_nii_image, path_to_save_destination)

```

So my question is how can I save the resliced nii image (what affine data should I use when saving) in the way that it is correctly/ displayed in 3D Slicer?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [December 14, 2017, 8:17pm UTC](https://discourse.slicer.org/t/reslicing-nifti-nii-file/1662/2 "2017-12-14T20:17:24Z")

</div>

Could you please post a full example of the issue using e.g. the MRhead dataset, or one of the [NIfTI test datasets]([https://nifti.nimh.nih.gov/nifti-1/data](https://nifti.nimh.nih.gov/nifti-1/data).
