[Insight-users] ITK ConstNeighborhoodIterator and NthElementI mageAdaptor Type Confusion

Miller, James V (Research) millerjv@crd.ge.com
Fri May 7 14:44:04 EDT 2004


I believe the NeighborhoodIterators do not support ImageAdaptors
(for efficiency reasons). 

>From the API of ConstNeighborhoodIterator, it looks as though
ImageAdaptors are supported.  However, the implementations of the 
access methods call operator[] on the superclass of
ConstNeighborhoodIterator. This superclass is a Neighborhood templated over
the InternalPixelType of the image. So even though the API to GetPixel()
says it returns a PixelType it attempts to return an InternalPixelType.

This explains your compiler error.

We will revisit the issue as to whether NeighborhoodIterators should support
adaptors and what the overhead will be.

Sorry for the confusion.

Jim




-----Original Message-----
From: Gunther H. Weber [mailto:Gunther.Weber@gmx.net]
Sent: Thursday, May 06, 2004 10:14 PM
To: insight-users@itk.org
Subject: [Insight-users] ITK ConstNeighborhoodIterator and
NthElementImageAdaptor Type Confusion


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;
   }
}

_______________________________________________
Insight-users mailing list
Insight-users@itk.org
http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list