[Insight-users] Writing functions for both images with vector pixels with images with scalar pixels

David Doria daviddoria at gmail.com
Sat Nov 20 15:01:53 EST 2010


I have a

itk::Image<itk::CovariantVector<float,N>, 2>

and a

itk::Image<float, 2>

and I want to write a template function to print all of the pixels, for example.

The following works fine for "scalar" images which are actually vector
images with pixel vector length = 1
( itk::Image<itk::CovariantVector<float,1>, 2>  )

template <typename TImageType>
void ITKImagetoVTKImage(typename TImageType::Pointer image)
{
 // iterate over the pixels...
 // for each pixel, iterate over the components
      for(unsigned int component = 0; component <
image->GetPixel(index).Size(); component++)
        {
        DoSomething(image->GetPixel(index)[component]);
        }
}

but .Size() and GetPixel(index)[component] don't work on actual scalar
images ( itk::Image<float, 2> )

Is there any way to avoid having to write this type of function twice
to handle both types of images?

Thanks,

David


More information about the Insight-users mailing list