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

Javier Juan Albarracín javij1 at gmail.com
Thu Jun 2 13:02:38 EDT 2016


Thank you for the quick anwser.

I am sorry but I do not clearly see how can I later work with the image 
and with the filters that need the ImageType to declare the object. In 
the [1] example, the "ReadScalarImage" function implements the long 
switch statement code to load the image with the corresponding type. 
However, I cannot return a pointer to the image because depending on the 
case statement, it has one type or another.

Inside each case statement the corresponding image type is known, so 
templated functions can be called and the image type can be inferred for 
each one. This means that I have to embed all my code, my function and 
methods calls inside each case statement to know the ImageType? Surely I 
am not understanding something because I don't believe this approach is 
correct.

Thank you very much.

Regards.

Javier.


El 02/06/2016 a las 17:59, Lowekamp, Bradley (NIH/NLM/LHC) [C] escribió:
> 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