[Insight-developers] file reader behavior

Damion Shelton dmshelto at andrew . cmu . edu
Tue, 06 Aug 2002 12:24:50 -0400


Quick question about image IO:

Until recently, the following code fragment worked fine.

  m_ImageReader = ImageFileReaderType::New();
  itk::MetaImageIOFactory::RegisterOneFactory();
  m_ImageReader->SetFileName( m_InputImageFilename );
  m_InputImage = m_ImageReader->GetOutput();
  m_InputImage->SetRequestedRegionToLargestPossibleRegion();
  m_ImageReader->Update();

Now, this crashes, but rewriting it in a slightly different way works.

  m_ImageReader = ImageFileReaderType::New();
  itk::MetaImageIO::Pointer metaIO;
  metaIO = itk::MetaImageIO::New();
  m_ImageReader->SetImageIO(metaIO);
  m_ImageReader->SetFileName(m_InputImageFilename);
  m_ImageReader->Update();
  m_InputImage = m_ImageReader->GetOutput();
  m_InputImage->SetRequestedRegionToLargestPossibleRegion();

Any ideas what's going on? The original code was very similar to 
MetaImageIOTest while the new version is closer to most of the other image 
tests (PNG, for instance). Which of the two styles (factory vs. SetImageIO) 
is "correct"?

Thanks,
-Damion-