[vtkusers] Iterating over an image and getting neighbors

David Doria daviddoria at gmail.com
Thu Sep 23 14:24:22 EDT 2010


I want to visit each pixel in an image (a 2D vtkImageData) and get its
4-connected neighbors. The tricky part (i.e. that makes it messy to do
directly in the algorithm) is that there is not always 4 valid
neighbors (you might be on the edge of the image).

Is there any built in mechanism for doing this? It would be very nice
to separate this logic from the core algorithm.

I saw vtkImageIterator but it just seems to move a pointer but not
know anything about neighborhoods:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Broken/ImageData/vtkImageIterator

I also saw vtkImageSpatialAlgorithm, but it doesn't seem to have any
concept of neighbors of a pixel either.

I'd like something like a

for(every pixel in the image)
{
 neighbors = pixel.GetNeighbors()
 if(neighbors.HasLeft())
  {do something with neighbors.GetLeft()}
}

Is there anything like this built in?

Thanks,

David



More information about the vtkusers mailing list