<div>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.</div><div><br></div><div><div>template <typename TImage></div>
<div>void OperateOnEveryChannel(const TImage* const image)</div><div>{</div><div> itk::Index<2> index = {{0,0}};</div><div> typename TImage::PixelType pixel = image->GetPixel(index);</div><div><br></div><div> for(unsigned int i = 0; i < image->GetNumberOfComponentsPerPixel(); ++i)</div>
<div> {</div><div> std::cout << pixel[i] << std::endl;</div><div> }</div><div>}</div></div><div><br></div><div>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.</div>
<div><br></div><div>Is there any way to do this without writing a specialization?</div><div><br></div>Thanks,<br><br>David<br>