[Insight-users] Need help for writting an image

Yankam Njiwa Josiane Adrienne njiwa at biomed.ee.ethz.ch
Wed Sep 3 04:23:32 EDT 2008


 

Hi Luis,

Thank you for your answer. Nothing is written after the writer->Update ();

I try the  

try

{

writer->Update();

}

catch( itk::ExceptionObject & excp )

{

std::cerr << excp << std::endl;

}

and the error message is the following:  File: ..\..\..\src\InsightToolkit-3.8.0\Code\IO\itkPNGImageIO.cxx
Line: 506
Description: itk::ERROR: PNGImageIO(01866840): Error while writing Slice to file:C:\Josiane\ITK\Projects\ICP\Results\Res.png
Reason: Domain error

Do you have any  idea on what is wrong? The source code is bellow.

Thanks a lot for your help.

Regards,

 

Josiane.

 

 

 

 

typedef unsigned char PixelType;

typedef itk::Image< PixelType, Dimension > ImageType;

typedef itk::ImageFileReader< ImageType > ImageReaderType;

ImageReaderType::Pointer ImageReader = ImageReaderType::New();

ImageReader->SetFileName( argv[3] );

 

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() );

resampler->SetOutputDirection( Image->GetDirection() );

resampler->SetDefaultPixelValue( 100 );

typedef itk::CastImageFilter< 

ImageType,

ImageType > CastFilterType;

typedef itk::ImageFileWriter< ImageType > WriterType;

WriterType::Pointer writer = WriterType::New();

CastFilterType::Pointer caster = CastFilterType::New();

caster->SetInput( resampler->GetOutput());

writer->SetInput( caster->GetOutput() );

writer->SetFileName( argv[4] );

try

{

writer->Update();

}

catch( itk::ExceptionObject & excp )

{

std::cerr << excp << std::endl;

}

 


________________________________

From: Luis Ibanez [mailto:luis.ibanez at kitware.com]
Sent: Tue 02/09/2008 20:51
To: Yankam Njiwa Josiane Adrienne
Cc: insight-users at itk.org
Subject: Re: [Insight-users] Need help for writting an image




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