MINC/Tutorials/Programming03

A fully functional and useful example
There are two programs that can be found inside the conglomerate package: print_volume_value and print_world_value. To use them you specify a minc volume and xyz coordinates in either voxel (volume) or world space, and it returns the real value at that location. Here we will combine that functionality into a single minc2 program.

The code is presented in its entirety below, with commentary at the end of this page. The usage is the following: > minc2_tutorial3 input.mnc v|w c1 c2 c3

Where v or w specify whether world or voxel coordinates are specified inside c1 c2 c3.

Most of this code you've seen in the two previous examples. There are a few additional minc library calls - the first is miconvert_voxel_to_world, which does the reverse of miconvert_world_to_voxel. There are also two functions that deal with dimensions. The first, miget_volume_dimensions, places the dimensions associated with the specified minc volume into a midimhandle_t variable. There are several arguments to this function; for the moment it is sufficient to note that the defaults used above will be fine for most cases (and the details will be discussed in a later tutorial). The next function is crucial - miget_dimension_sizes returns the number of elements in each dimension. This is crucial information for looping over voxels as will be illustrated later.

As stated above this code reproduces functionality that exists in print_volume_value and print_world_value. It does, however, illustrate one advantage of minc2 over volume_io (the older library used by those two programs): it is much faster, by as much as an order of magnitude for this example.