[Insight-users] ITK ConstNeighborhoodIterator and NthElementImageAdaptor Type Confusion

Gunther H. Weber Gunther.Weber@gmx.net
Fri May 7 03:13:53 EDT 2004


Hello,

I am trying to access individual components of an RGB image through an  
NthElementImageAdaptor and iterate over pixels in a neighborhood via a  
ConstNeighborhoodIterator. However, both the GetPixel(index) and  
GetCenterPixel() methods of the iterator seem to return an RGBPixel  
rather than the corresponding scalar type as I expected. Can anyone  
help me and tell me what I am doing wrong, please? An example program  
where this problem occurs is attached.

Thank you
    Gunther

---
#include <itkRGBPixel.h>
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkConstNeighborhoodIterator.h>
#include <itkNthElementImageAdaptor.h>

typedef itk::Image<itk::RGBPixel<float>, 2> FloatRGBImage;
typedef itk::ImageFileReader<FloatRGBImage> ReaderType;

int main(int argc, const char *argv[])
{
   if (argc !=2) {
     std::cerr << "Usage: " << argv[0] << " <inFilename>" << std::endl;
     return 1;
   }
   const char* inputFilename = argv[1];

   try {
     // Reader
     ReaderType::Pointer reader = ReaderType::New();
     reader->SetFileName(inputFilename);

     // Make sure image is read
     reader->Update();

     // Treat components independently
     itk::NthElementImageAdaptor<FloatRGBImage, float>::Pointer
       InputImageComponent = itk::NthElementImageAdaptor<FloatRGBImage,  
float>::New();
     InputImageComponent->SetImage(reader->GetOutput());

     // Select a component
     InputImageComponent->SelectNthElement(0);

     // Get a pixel
      
itk::ConstNeighborhoodIterator<itk:: 
NthElementImageAdaptor<FloatRGBImage, float> >::RadiusType  
neighborhoodRadius;
     neighborhoodRadius.Fill(5);
     float pixelVal;
      
itk::ConstNeighborhoodIterator<itk:: 
NthElementImageAdaptor<FloatRGBImage, float> >
       testIt(neighborhoodRadius, InputImageComponent,  
InputImageComponent->GetRequestedRegion());
     testIt.GoToBegin();
     pixelVal = testIt.GetCenterPixel(); // Complains that it cannot  
assign RGBPixel<float> to float! Why?
   }
   catch (itk::ExceptionObject& err) {
     std::cerr << "Exception object caught!" << std::endl;
     std::cerr << err << std::endl;
     return 42;
   }
}




More information about the Insight-users mailing list