<div class="gmail_quote">On Wed, Apr 27, 2011 at 8:57 AM, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word">Hello David,<div><br></div><div>We are implementing this independent per component filtering in SimpleITK for VectorImages.</div><div><br></div><div>I am curious as to what filters you are finding it useful to run on a per component basis, so that we can try to get those implemented in SimpleITK.</div>
<div><br></div><div>Here is a sample of how we are doing it, it sounds like the same way you are doing it:</div><div><br></div><div><div>template &lt;class TImageType&gt; Image</div><div>LogImageFilter::ExecuteInternalVectorImage ( const Image&amp; inImage1 )</div>
<div>{</div><div>  // Define the input and output image types</div><div>  typedef TImageType                                                                                    InputImageType;</div><div>  typedef typename InputImageType::InternalPixelType                         ComponentType;</div>
<div><br></div><div>  typedef typename itk::Image&lt;ComponentType, InputImageType::ImageDimension&gt; ComponentImageType;</div><div><br></div><div>  typedef InputImageType OutputImageType;</div><div><br></div><div>  // Get the pointer to the ITK image contained in image1</div>
<div>  typename InputImageType::ConstPointer image1 =</div><div>    dynamic_cast &lt;const InputImageType*&gt; ( inImage1.GetImageBase() );</div><div><br></div><div>  // Check that ITK image pointer was properly retrieved</div>
<div>  if ( image1.IsNull() )</div><div>    {</div><div>    sitkExceptionMacro( &quot;Unexpected template dispatch error!&quot; );</div><div>    }</div><div><br></div><div>  typedef itk::VectorIndexSelectionCastImageFilter&lt; InputImageType, OutputImageType &gt; ComponentExtratorType;</div>
<div>  typename ComponentExtratorType::Pointer extractor = ComponentExtratorType::New();</div><div>  extractor-&gt;SetInput( image1 );</div><div><br></div><div>  typedef itk::ImageToVectorImageFilter&lt;ComponentImageType&gt; ToVectorFilterType;</div>
<div>  typename ToVectorFilterType::Pointer toVector = ToVectorFilterType::New();</div><div><br></div><div>  unsigned int numComps = image1-&gt;GetNumberOfComponentsPerPixel();</div><div>  for ( unsigned int i = 0; i &lt; numComps; ++i )</div>
<div>    {</div><div>    extractor-&gt;SetIndex( i );</div><div>    extractor-&gt;Update();</div><div><br></div><div>    Image tmp = this-&gt;ExecuteInternal&lt;ComponentImageType&gt;( Image( extractor-&gt;GetOutput() ) );</div>
<div><br></div><div>    typename ComponentImageType::ConstPointer tempITKImage =</div><div>      dynamic_cast &lt;const ComponentImageType*&gt; ( tmp.GetImageBase() );</div><div><br></div><div>    toVector-&gt;SetNthInput( i, tempITKImage );</div>
<div>    }</div><div><br></div><div>  toVector-&gt;Update();</div><div><br></div><div>  return Image( toVector-&gt;GetOutput() );</div><div>}</div></div></div></blockquote><div><br>I&#39;ve needed it on RescaleImageIntensity, smoothing, logical operations 
(as sometimes a &quot;binary/mask&quot; image is really an RGB image with each 
channel identical), thresholding, etc.<br>
<br>I would go as far as to say all filters should be able to do this (without writing the loop in each one). I&#39;m going to take a look at Juliens solution now. <br>
<br clear="all">David<br></div><div> </div></div><br>