Use of itkImageIterator
Luis Ibanez
ibanez at cs.unc.edu
Mon May 1 15:57:48 EDT 2000
Hi,
We are trying to write our first simple algorithm,
but we get confused about how to use image
iterators in the way they are set now.
Our understanding is that an itkImageIterator
contains an itkIndex (an array of unsigned longs
with size equal to the dimension of the image).
The numbers in the index array are used to
address a particular element (pixel/voxel) of the
image.
This looks fine for getting access to a particular
pixel. But it is not very clear how to go through
the whole image.
This is what we tried:
==================================
typedef itkImage<char,2> imageType;
imageType *myImage = imageType::New();
imageType *myResult = imageType::New();
unsigned long int size[] = { 1024,1024 };
myImage->SetSize(size);
myResult->SetSize(size);
imageType::Iterator myIterator = myImage->Begin();
imageType::Iterator resultIterator = myResult->Begin();
// so far we have an iterator pointing to the upper left
// pixel of the image
// now... incrementing the iterator will move in the
// inner loop of the image memory array... and only
// there.
// now we recover the size of the image
// and create an index to jump in the vertical direction
// because itkImageIterators can be incremented by
// using itkIndex's
const unsigned int nx = myImage->GetSize()[0];
const unsigned int ny = myImage->GetSize()[1];
imageType::Index stepy;
stepy[1] = 1;
for(unsigned int y=0; y<ny; y++) {
imageType::Index start = myIterator->GetIndex()
start[0] = 0; // we didn't find other way to reset the
// inner loop part of the iterator/index
myIterator.SetIndex(start);
resultIterator.SetIndex(start);
for(unsigned int x=0; x<nx; x++) {
*resultIterator++ = *myIterator++;
}
myIterator += stepy;
resultIterator += stepy;
}
But this construction look unnatural and quite complex,
could somebody gives a hint about what are we missing ?
=================================
On the other hand, there is no an operator
operator!=
nor
operator==
So we cannot make expression like
while( iter != image->End() );
==================================
We are looking a little the implementation
done in Blitz++, to see if there are some
options.
Luis
More information about the Insight-developers
mailing list