[Insight-users] Question about MetaImages

Gavin Baker gavinb+xtk at cs.mu.OZ.AU
Fri Jul 23 20:38:53 EDT 2004


Hello Jacob,

On Fri, Jul 23, 2004 at 03:14:52PM -0800, Jacob Boomgaarden wrote:

> Just a quick question about reading MetaImage files.
> After creating a *.mhd header containing the necessary information to load
> a set of 2D slices as a volume, how do I actually read in an Image then?
> Must I instantiate an actual itk::MetaImage, or does the itk::Image class
> take care of the underlying work?

No, you use an itk::Image as normal, and an itk::ImageFileReader to load it.
A MetaImage file is one of the many formats supported, and there's nothing
special required to load it.  The file IO architecture supports pluggable
file modules, so you load and save all image files in the same way (unless
you need to acess some special feature for a particular format).

You can just use the itk::ImageFileReader class, as described in the "ITK
Software Guide" on PDF page 63.  Something like:

~~

  typedef unsigned char                        PixelType;
  unsigned int                                 Dimension = 2;
  typedef itk::Image< PixelType, Dimension >   ImageType;
  typedef itk::ImageFileReader< ImageType >    ReaderType;

  ReaderType::Pointer reader = ReaderType::New();

  reader->SetFileName( argv[1] );
  reader->Update();

~~

The itk::Image class knows nothing of the file format; it is purely the
in-memory representation, handling spacing, orientation, memory and so on.

The only time you might want to directly use itk::MetaImage is if you want
to use a specific feature of a MetaImage, that isn't provided by the IO
framework.  You can find some examples in the testing code for the MetaIO
library.

  :: Gavin

-- 
Gavin Baker                                      Complex Systems Group
http://www.cs.mu.oz.au/~gavinb             The University of Melbourne


More information about the Insight-users mailing list