# Extracting Slices from a 3D MRI volume using Reformat Module

**URL:** https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843
**Category:** Support
**Created:** [February 20, 2019, 1:03pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843 "2019-02-20T13:03:57Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nish91](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nish91](https://discourse.slicer.org/u/nish91)
#### Post date: [February 20, 2019, 1:03pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/1 "2019-02-20T13:03:57Z")

</div>

I used reformat module to fix an arbitrary plane using a normal vector and then visualized the slices by moving the plane on that normal. However, I am not able to extract all the slices from the defined plane and Reformat module only helps me in visualization of the intensities on those slices. Basically I would like to extract the slices containing the MRI intensities and store it in a 3D array for further processing. Please let me know how to solve this in 3D Slicer. Thanks

 ![Selection_073](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/e/9e75028f89ba45fa0036672552ac6476d0485174.png)

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [February 20, 2019, 1:36pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/2 "2019-02-20T13:36:18Z")

</div>

H @nish91 - there isn’t a built-in operation for this, but it can be done with a little programming and linear algebra. The Reformat operation changes the SliceToRAS matrix of the vtkMRMLSliceNode ([this documentation](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Slice_Orientation_Presets) should help. Then the information can be converted into a linear transform (maybe some modification needed) and then the volume can be resampled through the transform. You can then access the result volume as a numpy array.

Another option could be to use the ScreenCapture to get s movie of the slice viewer but you’d lose the geometry information.

---

<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: [February 20, 2019, 2:06pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/3 "2019-02-20T14:06:56Z")

</div>

You can also follow this example to get resliced image as a volume node and access it as a numpy array:

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get\_reformatted\_image\_from\_a\_slice\_viewer\_as\_numpy\_array](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_reformatted_image_from_a_slice_viewer_as_numpy_array)

---

<div class="post-metadata">

### Author: ![nish91](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nish91](https://discourse.slicer.org/u/nish91)
#### Post date: [February 20, 2019, 2:51pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/4 "2019-02-20T14:51:54Z")

</div>

Thanks @lassoan for your reply, This works for me. I would like to save this array out of 3D Slicer so that I can access the voxel in other environments. Do you know which command will do that in python interactor??

---

<div class="post-metadata">

### Author: ![nish91](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nish91](https://discourse.slicer.org/u/nish91)
#### Post date: [February 20, 2019, 2:53pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/5 "2019-02-20T14:53:56Z")

</div>

Thanks for the reply. I will try this solution too.

---

<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: [February 20, 2019, 3:08pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/6 "2019-02-20T15:08:48Z")

</div>

> [@nish91](#):
>
> This works for me. I would like to save this array out of 3D Slicer so that I can access the voxel in other environments

How you are going to use the image? In what software, what programming language/environment? What format do you usually use for storing images?

---

<div class="post-metadata">

### Author: ![nish91](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nish91](https://discourse.slicer.org/u/nish91)
#### Post date: [February 20, 2019, 3:13pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/7 "2019-02-20T15:13:16Z")

</div>

I am going to use the voxel array in Jupyter notebook and I don’t have Slicer installed in my notebook. Therefore my best bet is to extract these images out of python interactor in 3D Slicer. I will use these images to feed into a neural network. I prefer any format (such as TIFF etc) which preserves the gray scale intensities.

---

<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: [February 20, 2019, 3:20pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/8 "2019-02-20T15:20:53Z")

</div>

Thanks for the details. To preserve all information, I would recommend to save in .nrrd format using `slicer.util.saveNode(volumeNode, 'c:/tmp/myvolume.nrrd')`.

---

<div class="post-metadata">

### Author: ![nish91](https://avatars.discourse-cdn.com/v4/letter/n/da6949/32.png) [@nish91](https://discourse.slicer.org/u/nish91)
#### Post date: [February 20, 2019, 3:29pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/9 "2019-02-20T15:29:10Z")

</div>

Thanks a lot. This works for me 🙂

---

<div class="post-metadata">

### Author: ![Sharada](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sharada](https://discourse.slicer.org/u/Sharada)
#### Post date: [October 11, 2021, 11:12pm UTC](https://discourse.slicer.org/t/extracting-slices-from-a-3d-mri-volume-using-reformat-module/5843/10 "2021-10-11T23:12:50Z")

</div>

Hi Andras,

I am trying to achieve something similar, and the solution you recommended works fine for re-slicing images in a reformatted way, but is there a way to reformat and get voxel values for a whole volume?  
I saw that Steve Pieper mentioned that there is no built-in operation and a transformation might need to be created. Please let me know!

Thanks,  
Sharada
