[Insight-users] Reading a MINC1 image file using vtkMINCImageReader and converting it to ITK
Ricardo Ferrari
rjf.araraquara at gmail.com
Tue Sep 22 09:45:48 EDT 2009
Dear All,
I have coded the following template functions to read a MINC1 image file and
convert it ITK. The program compiles and runs
without any problem. However I am not sure if this would be the proper
manner to do this. I am also not so sure if I have created any memory leaks.
Could anybody please tell me if this okay?
Thank you,
RIcardo
///
************************************************************************************************************
/// Main program
///
************************************************************************************************************
/// Pixel type definition
typedef signed short PixelType;
/// Define type of the input and output images
typedef itk::Image< PixelType, 3 > ImageType;
int main( int argc, char **argv )
{
string inputFileName = "ImageDataMINC1.mnc";
ImageType::Pointer itkImage = ReadMinc1Image< ImageType >( inputFileName
);
return 0;
}
///
************************************************************************************************************
/// Convert ITK to VTK
///
************************************************************************************************************
template< typename TImageType >
vtkImageData *ConvertItkToVtk( typename TImageType::Pointer input )
{
typedef itk::ImageToVTKImageFilter< TImageType >
ImageToVTKImageFilterType;
typename ImageToVTKImageFilterType::Pointer connector =
ImageToVTKImageFilterType::New();
connector->SetInput( input );
connector->Register();
return connector->GetOutput();
}
///
************************************************************************************************************
/// Convert VTK to ITK image format
///
************************************************************************************************************
template< typename TImageType >
typename TImageType::Pointer ConvertVtkToItk( vtkImageData *img )
{
typedef itk::VTKImageToImageFilter< TImageType >
VTKImageToImageFilterType;
typename VTKImageToImageFilterType::Pointer connector =
VTKImageToImageFilterType::New();
connector->SetInput( img );
connector->GetImporter()->Update();
return connector->GetImporter()->GetOutput();
}
///
************************************************************************************************************
/// Read a MINC1 image file
///
************************************************************************************************************
template< typename TImageType >
typename TImageType::Pointer ReadMinc1Image( const std::string fileName )
{
vtkMINCImageReader *reader = vtkMINCImageReader::New();
reader->SetFileName( fileName.c_str() );
try
{
reader->Update();
}
catch ( itk::ExceptionObject & err )
{
std::cout << "Caught an exception: " << std::endl;
std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
throw err;
}
catch (... )
{
std::cout << "Error while reading in image" << fileName <<
std::endl;
throw;
}
return ConvertVtkToItk< TImageType >( reader->GetOutput() );
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090922/de89d69a/attachment.htm>
More information about the Insight-users
mailing list