[Insight-users] Get the number of components per pixel without reading image

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Nov 28 21:18:33 EST 2012


Dave,

If you are able to re-use the ImageIO, then just creating the correct ImageIO and plugging it into the correctly typed ImageFileReader would be more efficient as you wouldn't need to determine the ImageIO again. That process my iterate over a number of ImageIOs to determine the correct one.

Brad

On Nov 28, 2012, at 5:15 PM, David Doria <daviddoria at gmail.com> wrote:

> On Wed, Nov 28, 2012 at 5:09 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> Something like this:
>>     typedef itk::Image<unsigned char, 3> ImageType;
>>     itk::ImageFileReader<ImageType>::Pointer imageReader =
>>       itk::ImageFileReader<ImageType>::New();
>>     imageReader->SetFileName(fileName.c_str());
>>     imageReader->UpdateOutputInformation();
>> 
>>     pixelType = imageReader->GetImageIO()->GetPixelType();
>>     componentType = imageReader->GetImageIO()->GetComponentType();
> 
> Ah, that is good to know. But you had to know the "3" there ahead of
> time, right?
> 
> I actually just found ImageIOBase::GetNumberOfComponents() that does
> exactly what I was looking for:
> 
> itk::ImageIOBase::Pointer imageIO =
>       itk::ImageIOFactory::CreateImageIO(
>           filename.c_str(), itk::ImageIOFactory::ReadMode);
> unsigned int numComponents = imageIO->GetNumberOfComponents();
> 
> (I thought the Doxygen functions were sorted alphabetically, so I
> looked near the GetNumberOfDimensions() function here:
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageIOBase.html#pub-methods
> 
> but I guess they are not, because if you look down the page further it
> is indeed there.)
> 
> Is there any benefit of using one of these techniques over the other?
> 
> David
> _____________________________________
> 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://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list