# How to crop nifti files

**URL:** <https://discourse.slicer.org/t/how-to-crop-nifti-files/6065>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [March 7, 2019, 8:59pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065 "2019-03-07T20:59:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjortiz2](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjortiz2](https://discourse.slicer.org/u/rjortiz2)\
**Post date:** [March 7, 2019, 8:59pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/1 "2019-03-07T20:59:29Z")

</div>

I know this may be a simple solution, but how does one crop a nifti file of a brain? I am trying to remove the skull and I’ve been stuck at this issue for quite some time. I have used segmentation wizard (or segmentation) module to highlight the regions I don’t want cropped, but cannot seem to figure out what module to use to actually cropt the rest out. I really appreciate all of the help!

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [March 7, 2019, 9:49pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/2 "2019-03-07T21:49:44Z")

</div>

If you already done the segmentations of the regions that you want to remove, install the Segment Editor Extra Effects extension and use mask volume function to save a version of your volume with just the brain. Then you can use the Crop Volume if you still want to remove the empty background.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 7, 2019, 9:51pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/3 "2019-03-07T21:51:29Z")

</div>

If you need to remove the skull from MRI images, then you can use [SwissSkullStripper](https://www.slicer.org/wiki/Documentation/Nightly/Modules/SwissSkullStripper) extension. It removes the skull from the image completely automatically.

---

<div class="post-metadata">

**Author:** ![rjortiz2](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjortiz2](https://discourse.slicer.org/u/rjortiz2)\
**Post date:** [March 7, 2019, 9:56pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/4 "2019-03-07T21:56:24Z")

</div>

I forgot to mention that I am using rodent images, and SwissSkullStripper is probably human-based, correct?

---

<div class="post-metadata">

**Author:** ![rjortiz2](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjortiz2](https://discourse.slicer.org/u/rjortiz2)\
**Post date:** [March 7, 2019, 10:11pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/5 "2019-03-07T22:11:23Z")

</div>

Will the outcome of this process still be in nifti? Your method was great for cropping out the desired stuff, but I cannot seem to save it back as a nifti file again.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 7, 2019, 11:06pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/6 "2019-03-07T23:06:48Z")

</div>

The skull stripper should work for any species, just provide your own template (a single image volume and a corresponding brain segmentation).

The result can be save in many formats, including nifti (you can choose file format in the save dialog).

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [March 7, 2019, 11:08pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/7 "2019-03-07T23:08:05Z")

</div>

You can save the masked volume in any format slicer supports (including Nifti). Just use the save as dialog box.

---

<div class="post-metadata">

**Author:** ![rjortiz2](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rjortiz2](https://discourse.slicer.org/u/rjortiz2)\
**Post date:** [March 12, 2019, 7:25pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/8 "2019-03-12T19:25:51Z")

</div>

Update:

These files are multi-volume nifti and I am attaching a dropbox link of an example of my data.

So far, my steps include

1- MultiVolume Importer–\>Select folder where .nii file in–\>output node–\>create new MRML MultiVolume–\>click Import (Output node becomes a 200 frames NIfTI MultiVolume)  
2. MultiVolume Explorer Module–\>select input multivolume as 200 frames NIfTI MultiVolume (can click play)  
3. Segment editor module w/ segment editor extra effects add-on installed–\>segment portion I want  
4. Mask Volume (within segment editor)–\>save new dataset with only segmented region  
5. Crop volume module–\>apply (I am able to visualize the masked, cropped image exclusively.

**The problem occurs because I cannot save the masked cropped image into a .nii file, as the only options are .nrrd or .nhdr format.**

> **[KSIL\_17\_litter\_20\_male\_1\_1\_Scan26\_Reco1.nii](https://www.dropbox.com/s/6hhoo3u3bvlx9lx/KSIL_17_litter_20_male_1_1_Scan26_Reco1.nii?dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [March 12, 2019, 8:48pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/9 "2019-03-12T20:48:47Z")

</div>

If you need to export multivolume as a .nii file, that functionality is not available. You can only save multivolumes as .nhdr/.nrrd.

---

<div class="post-metadata">

**Author:** ![Tim\_othy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tim_othy/32/13159_2.png) [@Tim\_othy](https://discourse.slicer.org/u/Tim_othy)\
**Post date:** [November 17, 2021, 3:00pm UTC](https://discourse.slicer.org/t/how-to-crop-nifti-files/6065/10 "2021-11-17T15:00:41Z")

</div>

Try the brain extraction tool in FSL?

Or FreeSurfer?
