如题:
#include <iostream> #include <string> #include <itkImage.h> #include <itkImageFileReader.h> #include <itkImageIOFactory.h> #include<itkMetaImageIOFactory.h> #include<itkImageFileWriter.h> int main() { // 注册.mha文件IO //itk::ImageIOBase::RegisterDefaultIOFactory(); itk::MetaImageIOFactory::RegisterOneFactory(); // 定义图像类型 typedef itk::Image<unsigned char, 3> ImageType; // 创建图像读取器 typedef itk::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(".\0.mha"); // 读取图像 try { reader->Update(); // 获取图像信息 ImageType::Pointer image = reader->GetOutput(); ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize(); ImageType::SpacingType spacing = image->GetSpacing(); // 输出图像信息 std::cout << "Image size: " << size << std::endl; std::cout << "Image spacing: " << spacing << std::endl; typedef itk::ImageFileWriter<ImageType> FileWriterType; FileWriterType::Pointer w = FileWriterType::New(); w->SetFileName(".\1.mha"); w->SetInput(image); w->Update(); } catch (itk::ExceptionObject& ex) { std::cerr << "Exception caught: " << ex << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }
标签:itk,image,C++,mha,reader,include,ImageType,ITK From: https://www.cnblogs.com/0523jy/p/17802713.html