[Insight-users] writing out a 3D volume

David Brayford dbrayford at gmail.com
Wed Aug 10 12:53:51 EDT 2011


Hi,

I am trying to write out a 3D volume in ITK that is loaded in from
VTK. However, I am having trouble with conversion errors from const
even after looking at some examples.

	typedef itk::Image< InputPixelType,  Dimension >   InputImageType;
	typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;

	InputImageType::ConstPointer imagePtr;

	vtkImageData * vol = data->GetVolume()->getImageData();

	typedef itk::VTKImageToImageFilter<InputImageType> VTKToITKConnector;
    VTKToITKConnector::Pointer VTK_to_ITK_filter = VTKToITKConnector::New();

    VTK_to_ITK_filter->SetInput(vol);
    VTK_to_ITK_filter->Update();

	imagePtr = VTK_to_ITK_filter->GetOutput();

	typedef itk::ResampleImageFilter<InputImageType, InputImageType > FilterType;
	FilterType::Pointer filter = FilterType::New();
	filter->SetInput( imagePtr );
	filter->SetDefaultPixelValue( 0 );

	typedef itk::CastImageFilter< InputImageType, InputImageType > CastFilterType;
	CastFilterType::Pointer caster = CastFilterType::New();
	caster->SetInput( filter->GetOutput() );

	 // Write the output
	 typedef itk::ImageFileWriter< InputImageType::ConstPointer > WriterType;
	 WriterType::Pointer writer = WriterType::New();

         // problem "itk::image<type, type>" is incompatible with type
"const itk::image<type, type>"
	 writer->SetInput( caster->GetOutput() );


	 writer->SetFileName("output_volume.mhd");
	 writer->Update();


More information about the Insight-users mailing list