[Insight-users] ShapedNeighborhoodIterator problem

Dawood Masslawi masslawi at gmail.com
Sun Nov 14 05:42:36 EST 2010


David,
The iterator.IsAtEnd(); command is correct and is not the cause of
the crash but the fact that you are activating the offsets without
boundary checking can cause errors when you iterate over out of bound
pixels. To handle the boundary pixels more efficiently you should use
the FaceList which divides the image into boundary and non-boundary
regions so you won't have to check for boundaries. I took the liberty
of editing your code and also placed some comments, hope that helps.
regards,
Dawood

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


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101114/6b6ab08e/attachment.htm>


More information about the Insight-users mailing list