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

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


Well, sorry. I just now understand what you are referring. You are 
refering to start to work inside the function "ReadImage" of the [1] 
example (maybe changing his name to some more informative) as if it was 
the "main" function because inside this templated function we have the 
ImageType as the template arg. Yes, it solves my problem.

Anyway, it is a little bit anoying for me. Maybe I can load the image in 
double format to avoid truncation problems and perform a final casting 
to the original type, but surely, in some point I should pass through 
the long switch statement.

Thank you Brad

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