[ITK-users] Set image pixel type and dimension through IOBase methods

Lowekamp, Bradley (NIH/NLM/LHC) [C] blowekamp at mail.nih.gov
Thu Jun 2 11:59:36 EDT 2016


Hello,

To accomplish this in C++ you need to use this long switch statement in combination with template functions. It’s really not too bad. You only write the switch statement once and then just work in the template method [1].

Alternatively, SimpleITK has created a typeless layer on top of ITK so that the types can easily be dealt with at run-time. This interface can easily be used in Python.

Similarly, there are the ITK’s python bindings too, which use Pythons weak typing in combination with dictionaries to types all put together with a convent interface.


HTH,
Brad

[1] https://itk.org/ITKExamples/src/IO/ImageBase/ReadUnknownImageType/Documentation.html

> On Jun 2, 2016, at 11:39 AM, Javier Juan Albarracín <javij1 at gmail.com> wrote:
> 
> 
> Hello,
> 
> I have to read a NIfTI file and I don't know which pixel type has (int, double, char, etc). Thus, I am using an ImageIOBase object to retrieve the image information before loading it. I have followed the code of the ITK examples, which is something similar to
> 
> // NIfTI IO Factory
> itk::NiftiImageIOFactory::RegisterOneFactory();
> 
> // Typedefs
> typedef itk::ImageIOBase::IOComponentType PixelType;
> itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(filename, itk::ImageIOFactory::ReadMode);
> 
> imageIO->SetFileName(argv[1]);
> imageIO->ReadImageInformation();
> 
> Here I know the pixel type and the image dimensio through "imageIO->GetComponentType()"  and "imageIO->GetDimensions()". Hence, I wan to declare an image type with this parameters to work with it on my methods.
> I would know if there is some way to declare the image without performing a long "switch - case double, case int, case ..." code to declare the image type, i.e. something similar to this:
> 
> // I know this do not compile and it is wrong but something similar
> typedef itk::Image<imageIO->GetComponentType(), imageIO->GetDimensions()>  ImageType;
> 
> Thank you.
> Regards.
> Javier.
> 
> _____________________________________
> 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://public.kitware.com/mailman/listinfo/insight-users



More information about the Insight-users mailing list