转到内容

MINC/教程/part2

来自 Wikibooks,一个开放世界的开放书籍

从 ITK 读写 MINC2.0 图像非常非常简单。你将会看到!


#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();

非常重要的说明 如果你的图像具有“方向余弦”,并且你希望让 ITK(而不是 itkImage)将它们考虑在内,则必须使用 itkOrientedImage,否则将不会使用方向余弦。

华夏公益教科书