MINC/Tutorials/Programming06

Hyperslabs part 2
Onto more hyperslabs: we will once again do the same trick of adding one to every voxel. We'll do it slightly differently: this time we will get and set the hyperslab at every slice, using much less memory. And, for even more mincy goodness, we will use slice scaling for the output.

This code is unchanged from the last tutorial.

This time we create the volume before we start messing with the actual data. We also set slice scaling using miset_slice_scaling_flag - note that this has to come before micreate_volume_image. The rest is the same as before.

The loop over the data has become more complicated. We now allocate data for a hyperslab big enough to hold one slice, and we reuse the same array for every slice. We then get the hyperslab for every slice, do the same manipulation of the voxels while keeping track of slice specific min and max, and set the slice range. Then we put the modified hyperslab into the new volume, and move on to the next slice.

And we finish up in the same way as before.