MINC/SoftwareDevelopment/EZMINC/Tutorial

Opening minc file for writing
Minc file is a complex structure, many parameters have to be setup properly to produce meaningful file, the easies way is to copy them from another minc file:

Or, if another file is already open: syntaxhighlight lang="text" wrt.open(output_minc_file,rdr);

Or, if only the dimensions need to be preserved (create a file with voxels of type float, and 2D slices): syntaxhighlight lang="text" wrt.open(output_minc_file,rdr.info,2,NC_FLOAT);

Analyzing MINC file meta information
syntaxhighlight lang="text" std::cout<<"Dimensions:"<<std::endl << " Vector:"<<rdr.ndim(0)<<std::endl << " X:"<<rdr.ndim(1)<<" step:"<<rdr.nspacing(1)<<" start:"<<rdr.nstart(1)<<std::endl << " Y:"<<rdr.ndim(2)<<" step:"<<rdr.nspacing(2)<<" start:"<<rdr.nstart(2)<<std::endl << " Z:"<<rdr.ndim(3)<<" step:"<<rdr.nspacing(3)<<" start:"<<rdr.nstart(3)<<std::endl << " Time:"<<rdr.ndim(4)<<" step:"<<rdr.nspacing(4)<<" start:"<<rdr.nstart(4)<<std::endl; Note that these are physical parameters, which don't depend on the way how information is stored in a minc file syntaxhighlight lang="text" std::cout<<"Echo time:"<<rdr.att_value_double("acquisition","echo_time")[0]<<std::endl; Note: reading double attribute returns std::vector by value
 * Determining number of dimensions:
 * calculating the matrix size, resolution :
 * Output direction cosine matrix
 * Read a minc file history
 * Read a string attribute
 * Read a double attribute

Reading Image
Imaging data is stored as a multidimensional array of values a given type. Array is organized in slices (could be just one slice for the whole file), values stored inside the minc file may be normalized, see MINC/Reference for complete details. EZMINC was developed to hide the complexity of the data representation from programmer, but to allow complete control over how data is stored, if it is needed. There are several ways to read imaging information from a file using EZMINC library:

syntaxhighlight lang="text" using namespace minc; //.... simple_volume src; minc_1_reader rdr; rdr1.open(input_file); load_simple_volume (rdr,src); std::cout<<"Voxel at voxel coordinates (1,2,3) is "<
 * 2) include 
 * Reading a volume with a binary mask (or discrete labels)
 * Reading a 4D volume


 * reading the whole minc file as a single continuous buffer, organized with vector_dimension the fastest varying (if present), X,Y,Z, and time the slowest varyuing (if present)


 * reading the whole minc file voxel-by-voxel, in the order that data is stored inside file. This method is really usefull when working with big number of input files, and storing them all together in memory is problematic


 * lowest-level interface, reading the minc file slice-by-slice in the order that data is stored

Writing MINC file meta information
wrt.insert("patient","full_name","John Doe"); wrt.insert("acquisition","echo_time",0.120); //echo time was 120ms std::vector bvalues(64); //... wrt.insert("acquisition","bvalues",bvalues); wrt.copy_headers(rdr);
 * copying history NOTE: if using first for of minc_1_writer::open history will be copied automatically
 * Appending new line into MINC history
 * Write a string attribute
 * Writing a double attribute
 * Writing an array of double values
 * Copying all headers from another minc file

Writing Images

 * Simplest interface, using simple_volume or simple_4d_volume
 * Writing image from a continuous array
 * Using output iterator
 * lowest-level, writing image slice-by-slice