[ITK] [ITK-users] Exception when running IO example ImageReadCastWrite in Xcode

Matt McCormick matt.mccormick at kitware.com
Wed Apr 2 11:06:48 EDT 2014


Hi Ramon,


> So your example registers one factory, right?

It registers two factories.  One for MetaImage, and one for PNG.

> The lines below are
> responsible for that?
>
> itk::ObjectFactoryBase::CreateAllInstance( "itkImageIOBase" );

This does not do the registration.  It just lists what is registered.

> ...
> itk::MetaImageIOFactory::RegisterOneFactory();

This registers a MetaImageIO object.

>
> I took the file Code.cxx and built it in an Xcode project and linked to the
> ITK libs. I ran it, passing it an Analyze hdr file and got the following
> exception:
>
> When CMake is not used to register the IO classes, there are
> 0 IO objects available to the ImageFileReader.
>
> When we try to read a MetaImage, we will fail.
>
> After registering the MetaImageIO object, there are
> 1 IO objects available to the ImageFileReader.
>
> Now, when we try to read a MetaImage, we will Error:
> itk::ImageFileReaderException (0x100404798)
> Location: "virtual void itk::ImageFileReader<itk::Image<unsigned char,
> 2>, itk::DefaultConvertPixelTraits<unsigned char>
>>::GenerateOutputInformation() [TOutputImage = itk::Image<unsigned char, 2>,
> ConvertPixelTraits = itk::DefaultConvertPixelTraits<unsigned char>]"
> File: /temp/itk/Modules/IO/ImageBase/include/itkImageFileReader.hxx
> Line: 143
> Description:  Could not create IO object for file
> /temp/itk-sample/copied/T1_MAP.hdr
>   Tried to create one of the following:
>     MetaImageIO
>   You probably failed to set a file suffix, or
>     set the suffix to an unsupported type.
>
>
>
> Program ended with exit code: 1
>

As stated in the example,

  Every format desired to be supported by the reader
  must be registered.

The ImageIO that reads Analyze files much be registered::

  itk::AnalyzeImageIOFactory::RegisterOneFactor();

after including the appropriate header.

HTH,
Matt
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users



More information about the Community mailing list