MINC/Tutorials/part2
Appearance
Reading and Writing MINC2.0 images from ITK is very very simple.You'll see!
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkOrientedImage.h"
#include "itkImageIOFactory.h"
#include "itkMINC2ImageIOFactory.h"
#include "itkMINC2ImageIO.h"
typedef itk::Image<float, 3> ImageType;
/* READING */
typedef itk::MINC2ImageIO ImageIOType;
ImageIOType::Pointer minc2ImageIO = ImageIOType::New();
itk::ImageFileReader<myImage>::Pointer reader = itk::ImageFileReader<myImage>::New();
reader->SetFileName("/home/myimage.mnc");
reader->SetImageIO( minc2ImageIO );
reader->Update;
/* WRITING */
itk::ImageFileWriter< myImage >::Pointer writer = itk::ImageFileWriter<myImage>::New();
writer->SetFileName("/home/myimage.mnc");
writer->SetImageIO( minc2ImageIO );
writer->SetInput( reader->GetOutput() );
writer->Update();
VERY IMPORTANT NOTE If your image has "direction cosines" and you want ITK to take them into account instead of itkImage you must use itkOrientedImage OR the direction cosines will NOT be used.