欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ITK dicom序列读取写入

程序员文章站 2022-04-01 08:39:39
...

 

const unsigned int      Dimension = 3;
typedef itk::Image< float, Dimension >      ImageType;
typedef itk::ImageSeriesReader< ImageType >     ReaderType;

dicom序列读取

int getSerialReader(ReaderType::Pointer ** reader,char * path)
{
	typedef itk::GDCMImageIO                        ImageIOType;
	typedef itk::GDCMSeriesFileNames                NamesGeneratorType;
	ImageIOType::Pointer gdcmIO = ImageIOType::New();
	NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();

	namesGenerator->SetInputDirectory(path);    //输入目录
	const ReaderType::FileNamesContainer & filenames =
		namesGenerator->GetInputFileNames();

	ReaderType::Pointer fixReader =  (**reader);// ReaderType::New();
	fixReader->SetImageIO(gdcmIO);
	fixReader->SetFileNames(filenames);

	try
	{
		fixReader->Update();
	}
	catch (itk::ExceptionObject &excp)
	{
		std::cerr << "Exception thrown while writing the image" << std::endl;
		std::cerr << excp << std::endl;
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}

写入

typedef itk::ImageFileWriter< InputImageType >  Writer1Type;
	Writer1Type::Pointer writer = Writer1Type::New();
	writer->SetFileName("C:/output/lung.dcm");
	writer->SetInput(reader->GetOutput());

	try
	{
		writer->Update();
	}
	catch (itk::ExceptionObject & e)
	{
		std::cerr << "exception in file writer " << std::endl;
		std::cerr << e << std::endl;
		return EXIT_FAILURE;
	}

 

相关标签: ITK