[Insight-developers] extracting components of vector image

Miller, James V (Research) millerjv at crd . ge . com
Thu, 8 Aug 2002 15:48:58 -0400


Testing/Code/BasicFilters/itkAdaptImageFilterTest.cxx shows how create
an AdaptImageFilter using a pixel accessor that selects just the
red, green, or blue component of an RGBPixel image.

The AdaptImageFilter is general enough to work with any pixel accessor.
You could use an AdaptImageFilter instantiated to use the NthElementPixelAccessor to select an
individual component of a vector
image.

Jim





-----Original Message-----
From: Tessa Sundaram [mailto:tessa@rad.upenn.edu]
Sent: Thursday, August 08, 2002 3:21 PM
To: insight-developers@public.kitware.com
Subject: [Insight-developers] extracting components of vector image


Dear ITK gurus,

I'm trying to write a filter to extract one component of a vector image
(for use with displacement fields, etc.).  I've tried modifying the
CastImageFilter to create a VectorIndexSelectionCastImageFilter.
 However, I keep getting errors when I try to access the functor as
this->GetFunctor()  within the filter:

C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: error C2819: type 'itk::Functor::VectorIndexSelectionCast<class
itk::Vector<double,2>,float>' does not have an overloaded member
'operator ->'
        
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: while compiling class-template member function 'void __thiscall
itk::VectorIndexSelectionCastImageFilter<class itk::Image<class
itk::Vector<double,2>,2>,class itk::Image<float,2> >::SetIndex(unsigned
int)'
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: error C2227: left of '->SetIndex' must point to class/struct/union
        
C:\itk\Insight\Code\BasicFilters\itkVectorIndexSelectionCastImageFilter.h(82) 

: while compiling class-template member function 'void __thiscall
itk::VectorIndexSelectionCastImageFilter<class itk::Image<class
itk::Vector<double,2>,2>,class itk::Image<float,2> >::SetIndex(unsigned
int)'

I'm confused as to why this isn't working since I'm deriving from the
UnaryFunctorImageFilter.  The index selection filter code is attached,
and below is the method in which I'm trying to use it.  Any suggestions
are greatly appreciated - thanks!

void ImageRegLMEx::WriteDisplacementField(unsigned int index)
  // Outputs the displacement field for the index provided (0=x,1=y,2=z)
{
  // Initialize the caster to the displacement field
  IndexSelectCasterType::Pointer fieldCaster = IndexSelectCasterType::New();
  fieldCaster->SetInput( m_Field );
  fieldCaster->SetIndex( index );
  fieldCaster->Update();

  // Set up the output filename
  char* outfile = new char[strlen(m_DisplacementsFileName+10)];
  sprintf(outfile, "%s%c.raw", m_DisplacementsFileName, 'x'+index);
  std::cout << "Writing displacements (" << fieldCaster->GetIndex() <<
") to " << outfile;

  itk::RawImageIO<Float,2>::Pointer io = itk::RawImageIO<Float,2>::New();
  itk::ImageFileWriter<FloatImageType>::Pointer writer =
itk::ImageFileWriter<FloatImageType>::New();
  writer->SetImageIO(io);
  writer->SetFileName(outfile);
  writer->SetInput(fieldCaster->GetOutput());
  writer->Write();

  std::cout << "...done" << std::endl;
}

-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Tessa A. Sundaram
M.D./Ph.D. Candidate, Penn SOM/SEAS
tessa@mail.med.upenn.edu / tessa@seas.upenn.edu
http://mail.med.upenn.edu/~tessa

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%