[Insight-users] Need help for writting an image

Luis Ibanez luis.ibanez at kitware.com
Tue Sep 2 14:51:59 EDT 2008


Hi Josiene,


a) You are missing to catch exceptions with a try/catch block.
    All your calls to Update() method should be surrounded in the
    following way:

      try
       {
       filter->Update();
       }
      catch( itk::ExceptionObject & excp )
       {
       std::cerr << excp << std::endl;
       }

    The message printed out by the exception will give you
    a hint of what the problem is.



b) You have setting statements after calling the writer->Update();

 > writer->Update();
 > resampler->SetOutputDirection( Image->GetDirection() );
 > resampler->SetDefaultPixelValue( 100 );


    Did you post an incomplete section of your code ?

    Otherwise the last two statements do not have any effect.

    They should be called before you call writer->Update().



Please add the try/catch blocks, run it again,
and post to the list the messages that you get
from the Exceptions.



    Thanks


      Luis



=======================================
Yankam Njiwa Josiane Adrienne wrote:
>  
> Dear all,
>  
> I used the iterative closestPoint.cxx and after registration i would like to use the computed tranform and apply on an image and then write this image in a file. I have an error that the application requested a runtime to terminate in an unusual way and that i should contact the application's support team for more explanation.
>  
> Please here the source code i wrote for that should somebody help me please?
>  
> Thanks,
>  
> Josiane.
>  
>  
> #include "itkImage.h"
> 
> #include "itkImageFileReader.h"
> 
> #include "itkResampleImageFilter.h"
> 
> #include "itkCastImageFilter.h"
> 
> #include "itkImageFileWriter.h"
> 
>  
> typedef unsigned short PixelType;
> 
> typedef itk::Image< PixelType, Dimension > ImageType;
> 
> typedef itk::ImageFileReader< ImageType > ImageReaderType;
> 
> ImageReaderType::Pointer ImageReader = ImageReaderType::New();
> 
> ImageReader->SetFileName( argv[4] );
> 
> ImageReader->Update();
> 
> typedef itk::ResampleImageFilter< 
> 
> ImageType, 
> 
> ImageType > ResampleFilterType;
> 
> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
> 
> resampler->SetInput( ImageReader->GetOutput() );
> 
> resampler->SetTransform( registration->GetTransform() );
> 
> ImageType::Pointer Image = ImageReader->GetOutput();
> 
> resampler->SetSize( Image->GetLargestPossibleRegion().GetSize() );
> 
> resampler->SetOutputOrigin( Image->GetOrigin() );
> 
> resampler->SetOutputSpacing( Image->GetSpacing() );
> 
> typedef itk::CastImageFilter< 
> 
> ImageType,
> 
> ImageType > CastFilterType;
> 
> typedef itk::ImageFileWriter< ImageType > WriterType;
> 
> WriterType::Pointer writer = WriterType::New();
> 
> CastFilterType::Pointer caster = CastFilterType::New();
> 
> writer->SetFileName( argv[5] );
> 
> caster->SetInput( resampler->GetOutput());
> 
> writer->SetInput( caster->GetOutput() );
> 
> writer->Update();
> 
>  
> 
>  
> 
> resampler->SetOutputDirection( Image->GetDirection() );
> 
> resampler->SetDefaultPixelValue( 100 );
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


More information about the Insight-users mailing list