[Insight-users] Accessing a POD pixel value as if it were the 0th component of a vector pixel type
David Doria
daviddoria at gmail.com
Wed Jan 4 15:16:19 EST 2012
I often have the case where I want a function template to operate on all
channels of an image. I'd like to be able to pass both a scalar image and a
vector image to the function.
template <typename TImage>
void OperateOnEveryChannel(const TImage* const image)
{
itk::Index<2> index = {{0,0}};
typename TImage::PixelType pixel = image->GetPixel(index);
for(unsigned int i = 0; i < image->GetNumberOfComponentsPerPixel(); ++i)
{
std::cout << pixel[i] << std::endl;
}
}
If TImage is an itk::VectorImage, all is well. However, if TImage is an
itk::Image<POD>, the scalar pixel types do not have an operator[], so
although pixel[0] makes logical sense from the algorithm's perspective, it
is not valid syntax.
Is there any way to do this without writing a specialization?
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120104/8823d8ce/attachment.htm>
More information about the Insight-users
mailing list