[Insight-users] Iterate on image columns

Emmanuel Christophe emmanuel.christophe at gmail.com
Thu Oct 4 11:41:33 EDT 2007


Hi all,

I was looking for an iterator flexible enough to go through an image
line by line (as usual) but also column by column.

I found the itk::ImageSliceConstIteratorWithIndex with the method
SetFirstDirection() and SetSecondDirection() which exactly does that.

However, when trying to use this iterator as usual:

  while (!inputIterator.IsAtEnd())
  {
        inputIterator.Get();
        ++inputIterator;
  }

I quickly ran into a segfault.

It appears that this iterator has to be used in a slightly more complicated way:

  while (!inputIterator.IsAtEnd())
  {
    while (!inputIterator.IsAtEndOfSlice())
    {
      while(!inputIterator.IsAtEndOfLine())
      {
        inputIterator.Get();
        ++inputIterator;
      }
      inputIterator.NextLine();
    }
  inputIterator.NextSlice();
  }

Wouldn't it be possible to add the IsAtEndOfLine() and
IsAtEndOfSlice() tests directly into the operator++ ?

It wouldn't modify the overall complexity as the test has to be done
anyway in the while loop.

Regards,
Emmanuel Christophe


More information about the Insight-users mailing list