[Insight-users] ShapedNeighborhoodIterator problem

David Doria daviddoria at gmail.com
Sat Nov 13 18:12:34 EST 2010


Hi all,

I've been trying for quite a while to use the
ShapedNeighborhoodIterator. I want to move the pixels of a 4-connected
"cross" over the image. After looking through the examples and tests,
I came up with this:

http://www.vtk.org/Wiki/ITK/Examples/Broken/Images/ShapedNeighborhoodIterator

but it seems to crash when the iterator.IsAtEnd() function is called.
Stepping through that function, it seems like the center pixel is not
defined? I thought the iterator would take care of this? I tried
manually activating the "center" (0,0) offset, but it did not change
the behavior.

Can anyone see where I am going wrong?

Also, once this basic iteration works, what is the "correct" way to
handle the borders of image? For example, when iterating over the top
row of the image, the "top" pixel of the cross will be invalid. Do I
specify the region to iterate as the (width-1)(height-1) region
centered on the image, then manually reset the iterator to do the
top/bottom/left/right rows and columns manually (where this time in
the loop I know which pixels will be valid? Or is there a more
automatic way? I see that the neighborhoodIterator is templated on a
boundary condition, but it seems I would still have to do this:

// setup iterator with ConstantBoundaryCondition = -1
while(!iterator.IsAtEnd())
{
if(the pixel returns -1)
 { skip it because it is out of bounds}
}

I thought the whole point of handling the boundary condition in the
iterator is to not have to have a conditional in this inner loop?

Thanks,

David


More information about the Insight-users mailing list