[Insight-users] Exception of read image

Julien Jomier jjomier at cs.unc.edu
Mon Nov 29 13:42:36 EST 2004


Hi Jimmy,

ITK image reader/writer throws an exception when it cannot read/write a
file.
An easy way to determine the cause of the problem is to add a try/catch
statement around the reader:

  try 
    { 
    readerA->Update();
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return;
    } 

Also, take a look at the Wiki FAQ:
http://www.itk.org/Wiki/ITK_FAQ#I_got_the_message:_.22Could_not_create_IO_ob
ject_for_file.22

Julien

> -----Original Message-----
> From: insight-users-bounces at itk.org 
> [mailto:insight-users-bounces at itk.org] On Behalf Of Jimmy Wong
> Sent: Monday, November 29, 2004 9:18 AM
> To: insight-users at itk.org
> Subject: [Insight-users] Exception of read image
> 
> 
> Dear itk users:
> 
> I have such an exception :
> 
> "Unhandled exception at 0x77e738b2 in myJRS.exe: Microsoft 
> C++ exception: 
> itk::ImageFileReaderException @0x00fbf748"
> 
> and the pointer points to the "std::ifstream readTester" in 
> itkimagefilereader.txx
> 
> My code:
> ============================================
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> 
> #include "itkScalarImageToListAdaptor.h"
> 
> const    unsigned int    Dimension = 2;
> typedef  unsigned char   PixelType;
> 
> typedef itk::Image< PixelType, Dimension >	ImageType;
> 
> typedef itk::ImageFileReader< ImageType >	ReaderType;
> 
> typedef itk::Statistics::ScalarImageToListAdaptor< ImageType 
> > SampleType;
> 
> 
> 
> const char * InputImageName[]  = {"A.png", "B.png"};
> 
> int main()
> {
> 	// Read source images
> 	ReaderType::Pointer readerA = ReaderType::New();
> 	ReaderType::Pointer readerB = ReaderType::New();
> 	readerA->SetFileName( InputImageName[0] );
> 	readerB->SetFileName( InputImageName[1] );
> 
> 	readerA->Update();
> 	ImageType::Pointer image = readerA->GetOutput();
> 
> 	SampleType::Pointer sample = SampleType::New();
> 	sample->SetImage(image);
> 
> 
> 	return 0;
> }
> ==============================================
> 
> What's wrong with it? Anyone has idea of this one?
> 
> Thanks.
> 
> 
> _______________________________________________
> 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