[Insight-users] Get the number of components per pixel without reading image
David Doria
daviddoria at gmail.com
Wed Nov 28 17:15:44 EST 2012
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
More information about the Insight-users
mailing list