<div>I often have the case where I want a function template to operate on all channels of an image. I&#39;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 &lt;typename TImage&gt;</div>
<div>void OperateOnEveryChannel(const TImage* const image)</div><div>{</div><div>  itk::Index&lt;2&gt; index = {{0,0}};</div><div>  typename TImage::PixelType pixel = image-&gt;GetPixel(index);</div><div><br></div><div>  for(unsigned int i = 0; i &lt; image-&gt;GetNumberOfComponentsPerPixel(); ++i)</div>
<div>    {</div><div>    std::cout &lt;&lt; pixel[i] &lt;&lt; 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&lt;POD&gt;, the scalar pixel types do not have an operator[], so although pixel[0] makes logical sense from the algorithm&#39;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>