#include "minc_1_rw.h" using namespace minc; //... try { minc_1_reader rdr; rdr.open(input_minc_file); } catch (const minc::generic_error & err) { std::cerr << "Got an error at:" << err.file () << ":" << err.line () << std::endl; std::cerr << err.msg()< 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);  Determining number of dimensions: rdr.dim_no() calculating the matrix size, resolution : syntaxhighlight lang="text" std::cout<<"Dimensions:"< Note that these are physical parameters, which don't depend on the way how information is stored in a minc file Output direction cosine matrix for(int i=0;i<3;i++) { if(rdr.have_dir_cos(i)) for(int j=0;j<3;j++) std::cout< Note: reading double attribute returns std::vector by value 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: The easiest, the whole volume is copied into a multidimensional array in memory. Usually this is the most convenient method: Reading a volume representing real values (interpret them as float) syntaxhighlight lang="text" #include  #include  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 "<(1.0,2.0,3.0)))< Reading a volume with a binary mask (or discrete labels) #include  #include  #include  using namespace minc; //.... simple_volume src; minc_1_reader rdr; rdr1.open(input_file); load_simple_volume(rdr,src); std::cout<<"Labels at (1,2,3) is "<<(int)src.get(1,2,3)< vol; load_4d_volume(rdr,vol); std::cout<<"Voxel at voxel coordinates (1,2,3) slice 0 is "< #include  using namespace minc; //... minc_1_reader rdr; rdr.open(input_file); rdr.setup_read_float(); //we have to setup the file to a proper data type size_t size=1; for(i=0;i(rdr,array); 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 #include  #include  using namespace minc; //... minc_1_reader rdr; rdr.open(input_file); rdr.setup_read_float(); //we have to setup the file to a proper data type minc_input_iterator in(rdr); double avg=0; int cnt=0; for(in.begin();!in.last();in.next()) { avg+=in.value() cnt++; } std::cout<<"Average value="< using namespace minc; //... minc_1_reader rdr; rdr.open(input_file); rdr.setup_read_float(); //we have to setup the file to a proper data type float* slice_buffer=new float[rdr.slice_len()]; for(rdr.begin();!rdr.last();rdr.next_slice())//minc_1_reader is actually an iterator! { rdr.read(slice_buffer); //do something usefull with the data } copying history NOTE: if using first for of minc_1_writer::open history will be copied automatically wrt.copy_headers(rdr); Appending new line into MINC history wrt.append_history("minc_test was used to produce this file\n"); Write a string attribute wrt.insert("patient","full_name","John Doe"); Writing a double attribute wrt.insert("acquisition","echo_time",0.120); //echo time was 120ms Writing an array of double values std::vector bvalues(64); //... wrt.insert("acquisition","bvalues",bvalues); Copying all headers from another minc file wrt.copy_headers(rdr); Simplest interface, using simple_volume or simple_4d_volume simple_volume output_vol; //... minc_1_writer wrt; wrt.open(output_minc,rdr); save_simple_volume(wrt,output_vol); simple_4d_volume output_vol; //... minc_1_writer wrt; wrt.open(output_minc,rdr); save_4d_volume(wrt,vol); Writing image from a continuous array float *output_vol=new float[size]; //... minc_1_writer wrt; wrt.open(output_minc,rdr); wrt.setup_write_float(); //have to setup the data type save_standard_volume(wrt,output_vol); Using output iterator //adding a value c to all voxels minc_1_reader rdr; rdr.open(input_minc); rdr.setup_read_float(); minc_1_writer wrt; wrt.open(output_minc,rdr); wrt.setup_write_float(); minc_input_iterator in(rdr); minc_output_iterator out(wrt); for(in.begin(),out.begin();!in.last();in.next(),out.next()) { out.value(in.value()+c); } lowest-level, writing image slice-by-slice #include  using namespace minc; //... minc_1_reader rdr; rdr.open(input_file); rdr.setup_read_float(); //we have to setup the file to a proper data type minc_1_writer wrt; wrt.open(output_minc,rdr); wrt.setup_write_float(); float* slice_buffer=new float[rdr.slice_len()]; for(rdr.begin(),wrt.begin();!rdr.last();rdr.next_slice(),wrt.next_slice()) { rdr.read(slice_buffer); //do something usefull with the data wrt.write(slice_buffer); }
{'wiki_source': 'wikibooks', 'other_info': "{'content_model': 'wikitext', 'language': 'en', 'title': 'MINC/SoftwareDevelopment/EZMINC/Tutorial', 'type': 'text'}"}