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

Luis Ibanez luis . ibanez at kitware . com
Thu, 07 Aug 2003 11:21:32 -0400


Hi Charanpal,

Once you read the image, you check the image size array.

with something like

reader->Update();

ImageType::SizeType size =
   reader->GetOutput()->GetLargestPossibleRegion().GetSize();


The "size" array will have N components, you
then count how many components have size[i] > 1.

The actual image dimension will be equal to the
number of components of the "size" array, with
values != 1.

eg.

unsigned int imageDimension=0;
for(unsigned int i=0; i< maxdimension; i++)
   {
   if( size[i] != 1 ) imageDimension++;
   }

std::cout << imageDimension << std::endl;



Regards,


    Luis



-------------------------------------------
Charanpal Dhanjal wrote:
> Hi Luis,
> 
> I'm using the gipl file format, although I also have some data in png
> format.
> 
> I understand what you said about templating a class containing the pipeline
> over dimension. I'm not sure about the method you suggested for figuring out
> the input dimensionality. How could I determine if the image is a degenerate
> volume with a single slice? Could I just pick a point in the image that's
> likely to be inside the volume and check if it has a value? Is there a more
> generic method?
> 
> Thanks,
> 
> Charanpal
> 
> ----- Original Message ----- 
> From: "Luis Ibanez" <luis . ibanez at kitware . com>
> To: "Charanpal Dhanjal" <csd172 at yahoo . co . uk>
> Cc: <insight-users at itk . org>
> Sent: Thursday, August 07, 2003 3:22 PM
> Subject: Re: [Insight-users] Beginners question on loading images of any
> dimension
> 
> 
> 
>>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
>>>
>>
>>
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk . org
>>http://www . itk . org/mailman/listinfo/insight-users
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>