[Insight-users] Beginners question on loading images of any dimension

Charanpal Dhanjal csd172 at yahoo . co . uk
Thu, 7 Aug 2003 11:41:02 +0100


How can I get an ITK ImageFileReader to read both a
3D and 2D image in the same code depending on the input it gets. At the
moment, I need to write something like this:

  typedef unsigned short      PixelType;
  const   unsigned int        Dimension = 2;
  typedef itk::Image< PixelType, Dimension >    ImageType;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  reader->SetFileName( inputFilename  );

But the dimension of the image is defined as part of the template of
ImageFileReader. Is there some way to find out the dimension of an image
before we create the ImageFileReader? Or is there some alternative way to
get ITK to load an image without specifying the dimension beforehand? At the
moment ITK crashes if I try to, say load a 2D image with a 3D
ImageFileReader type.

Thanks in advance for your help,

Charanpal