ITK dicom序列读取写入

 

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 翻转

     //结果显示
       typedef itk::FlipImageFilter< InternalImageType > FlipFilterType;
       typedef FlipFilterType::FlipAxesArrayType FlipAxesArrayType;
      FlipFilterType::Pointer filter = FlipFilterType::New();
      FlipAxesArrayType flipArray;
        flipArray[0] =0;
      flipArray[1] =1;
      filter->SetFlipAxes( flipArray );
      filter->SetInput( medianFilter->GetOutput() );

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页