MINC/Tutorials/PythonSliceLoop

A slice loop example using pyminc
When you open a volume in pyminc, none of the data is read until you access the .data variable. This means that you can open lots of volumes at the same time, and then selectively get a hyperslab out in order to conserve memory. The example below reads a bunch of volumes to find the mode (most common voxel) at every point - a simplistic voxel voting scheme for segmentation. A few comments are in the text, more explanation follows:

The key steps in this slice loop is to create an array of all the MINC volume handles, an an array which holds one slice for all volumes, and then to loop over all slices. At every slice the array is refilled with the current slice from each volume, the stat (mode in this case) is computed, and the results inserted into the output volumes.