MINC/SoftwareDevelopment/EZMINC/ITK Integration

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Better MINC1/2 support for ITK

[edit | edit source]

If you are not satisfied with MINC2 only interface provided by ITK, or need access to MINC file attributes, or want to read/write 4D data use ITK interface provided by EZMINC

Installing

[edit | edit source]

Compile EZMINC with ITK support, see [EZMINC_Installing] If you are not using ITK plugin (currently plugin is not recommended) add following code to "mincify" your ITK program:

 #include "itkMincImageIOFactory.h" 
 #include "itkMincImageIO.h"
 //....
 int main(int argc,char **argv)
 {
   //registering the MINC_IO factory
   itk::ObjectFactoryBase::RegisterFactory(itk::MincImageIOFactory::New()); 
   //....

Example of working with DTI data

[edit | edit source]

Code from itk_dti.cpp from examples:

Using minc XFM files

[edit | edit source]
  • applying transformation

code from itk_resample.cpp

#include "itkMincImageIOFactory.h"
 #include "itkMincImageIO.h"
 #include "minc_helpers.h"

 typedef itk::ResampleImageFilter<minc::image3d, minc::image3d> FilterType;
 typedef minc::XfmTransform  TransformType;
 //...
 TransformType::Pointer transform = TransformType::New();
 //reading a minc style xfm file
 transform->OpenXfm(xfm_f.c_str());
 transform->Invert();
 filter->SetTransform( transform );
 //...
  • Storing affine transformation in .xfm file
#include <minc_helpers.h>
 //...
 itk::AffineTransform<double,3>  m_AffineTransform;
 //...
 minc::write_linear_xfm(output_xfm, m_AffineTransform->GetMatrix(), m_AffineTransform->GetOffset());
  • Reading affine transformation from .xfm file
itk::AffineTransform<double,3>  m_AffineTransform;
 //...
 itk::Matrix<double,3,3> rotation;
 itk::Vector<double,3> translation;
 read_linear_xfm(input_xfm,rotation,translation);
 //...
 m_AffineTransform.SetOffset(translation);
 m_AffineTransform.SetMatrix(rotation);
  • reading/writing .tag files
std::vector<int> labels;
  std::vector<itk::Point<double>,3> tags;
  read_tags(tags, labels, input_tag);
  //....
  write_tags(tags, labels, ouput_tag);