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

Luis Ibanez luis . ibanez at kitware . com
Thu, 07 Aug 2003 10:22:22 -0400


Hi Charanpal,

You don't want to do that in a medical image
application. The dimensionality of the data
is fundamental characteristic of the image.

When you design the processing pipeline for a
particular medical application, the data
dimensionality is one of the first requirements
to be defined.

If your application is performing a processing
generic enough to be used in any data dimension,
you can encapsulate the ITK pipeline in a class
templated over dimension. Then, you instantiate
this class for both 2D and 3D, so your application
has internally a full 2D pipeline and a full 3D
pipeline.

For figuring out the dimensionality of the input
data you could instantiate a ImageFileReader of
the maximum dimension expected. Do *not* plug
this reader to any pipeline, since the crash is
probably caused by the subsequent filters, not
the reader itself.

Loading a 2D image with a 3D ImageFileReader should
work. It should return a degenerate volume with
a single slice.

What file format are you using for input ?



   Luis



--------------------------------------------
Charanpal Dhanjal wrote:
> 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
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>