[Insight-users] Filtering all channels of a VectorImage

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Apr 27 08:57:54 EDT 2011


Hello David,

We are implementing this independent per component filtering in SimpleITK for VectorImages.

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.

Here is a sample of how we are doing it, it sounds like the same way you are doing it:

template <class TImageType> Image
LogImageFilter::ExecuteInternalVectorImage ( const Image& inImage1 )
{
  // Define the input and output image types
  typedef TImageType                                                                                    InputImageType;
  typedef typename InputImageType::InternalPixelType                         ComponentType;

  typedef typename itk::Image<ComponentType, InputImageType::ImageDimension> ComponentImageType;

  typedef InputImageType OutputImageType;

  // Get the pointer to the ITK image contained in image1
  typename InputImageType::ConstPointer image1 =
    dynamic_cast <const InputImageType*> ( inImage1.GetImageBase() );

  // Check that ITK image pointer was properly retrieved
  if ( image1.IsNull() )
    {
    sitkExceptionMacro( "Unexpected template dispatch error!" );
    }

  typedef itk::VectorIndexSelectionCastImageFilter< InputImageType, OutputImageType > ComponentExtratorType;
  typename ComponentExtratorType::Pointer extractor = ComponentExtratorType::New();
  extractor->SetInput( image1 );

  typedef itk::ImageToVectorImageFilter<ComponentImageType> ToVectorFilterType;
  typename ToVectorFilterType::Pointer toVector = ToVectorFilterType::New();

  unsigned int numComps = image1->GetNumberOfComponentsPerPixel();
  for ( unsigned int i = 0; i < numComps; ++i )
    {
    extractor->SetIndex( i );
    extractor->Update();

    Image tmp = this->ExecuteInternal<ComponentImageType>( Image( extractor->GetOutput() ) );

    typename ComponentImageType::ConstPointer tempITKImage =
      dynamic_cast <const ComponentImageType*> ( tmp.GetImageBase() );

    toVector->SetNthInput( i, tempITKImage );
    }

  toVector->Update();

  return Image( toVector->GetOutput() );
}



On Apr 26, 2011, at 9:07 PM, David Doria wrote:

> Lately I've needed to run some filters on a VectorImage. The filters only work on single channel inputs. To get around this, my process to filter each channel separately has been:
> 
> 1) Use VectorIndexSelectionCastImageFilter to decompose the image into its separate channels
> 2) In a loop, run a filter on each channel
> 3) Use ImageToVectorImageFilter to assemble the output from the output of the filter on each channel.
> 
> Is this a reasonable process? Is a more automated way to do this?
> 
> Thanks,
> 
> David
> <ATT00001..txt>

========================================================
Bradley Lowekamp  
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110427/d53025da/attachment.htm>


More information about the Insight-users mailing list