Does Slicer Allow Us to Export a Single Slice?

Is there a way in Slicer to export the currently displayed (and likely reformatted) slice of a volume to an output file?
For example, I have loaded a double-oblique DICOM, and I am viewing the volume in an axial orientation in Slicer. I “scroll through” the slices of the volume to a slice of interest, and now I would like to export that slice. Preferably to a text file. Is this possible?
Thank you,

Probably this question is better suited to the 3D Slicer forum, but I answer here anyway.

In 3D Slicer, You can save the frame as it is displayed using Screen Capture module (using GUI or Python scripting).

However, probably what you need is not the displayed image (with annotations, overlays, etc.) but the resliced input volume as a vtkImageData or numpy array (this example shows how).

Text file is for humans to read, so if your image contains more than a few hundred pixels then you should not ever think about saving it as text file, because you’ll not be able to read it and it is a very bad file format otherwise (wastes storage space and very slow to read/write). Instead, save it in a standard image file format if you want to view it as an image; or get it as a numpy array if you want to manually inspect, slice, or plot parts of it.

Thank you, Andras. I apologize for not posting my question in the appropriate forum.
You are correct that what I am really after is the vtkImageData or numpy array. Using the example that you pointed me to, I was able to figure out how to export the data and save it to a .npy file. I had never used the Python interpreter from within Slicer, so that was new. Now I just need to figure out how to read the .npy file in C++.

  • Michelle

Numpy is great for processing data, but I would not use numpy to save the array. because .npy files are not easy to read/write it without numpy. Instead, you can use a standard research image file format, such metaimage, as it is very simple and VTK and many other libraries has readers/writers for it (see vtkMetaImageWriter).