[Insight-users] ShapedNeighborhoodIterator: how to get indexes and how to check bounds?

Dawood Masslawi masslawi at gmail.com
Sat Mar 19 09:24:59 EDT 2011


Hi Hugues,
Welcome to the ITK mailing list :)
ImageBoundaryFacesCalculator divides the image into two main regions, boundary and
non-boundary. For the non-boundary region no bound checking will be performed and only
the pixels in boundary regions are bound checked. You can easily access the pixels in
those regions by neighborhood iterators, using the ImageBoundaryFacesCalculator will
save you the effort for bound checking. For more information take a look at the following
link,
http://www.itk.org/Doxygen/html/structitk_1_1NeighborhoodAlgorithm_1_1ImageBoundaryFacesCalculator.html

The "ci" variable refers to the constant iterator which iterates over the neighborhood
defined by the neighborhood iterator and it does not have a GetIndex() method, instead
you can get its offset or neighborhood index and find its position relative to the center pixel
of the neighborhood. Page 722 of the ITK software guide illustrates how offsets and 
neighborhood indexes are identified relative to the center pixel.
Hope this helps,
Dawood

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Dear all,

 

It is my first post on the list and perhaps my question has already been
answered previously, albeit I couldn't find where. I'd be glad if you could
help even with a link.

I'm implementing a filter similar to the one found in
Examples\Iterators\ShapedNeighborhoodIterators1.cxx

 

[1] I understand that the advantage of the
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator is to lighten the burden
of the algorithm where no check for bounds is necessary.

However in the (inner) loop of the ShapedNeighborhoodIterator, no bounds are
checked; instead all neighbors are visited (even those falling outside of
the image).

How can I check for this?

 

[2] In the (inner) loop of the ShapedNeighborhoodIterator, I can get the
values of the pixels with ci.Get() .

How can I get the indexes? The GetIndex method does not work.

 

Thank you for your time,

 

Hugues

 

Here is my code:

 

  typedef itk::ShapedNeighborhoodIterator< ImageType >
ShapedNeighborhoodIteratorType;

  ShapedNeighborhoodIteratorType::OffsetType top = {{0,-1}};

  ShapedNeighborhoodIteratorType::OffsetType bottom = {{0,1}};

  ShapedNeighborhoodIteratorType::OffsetType left = {{-1,0}};

  ShapedNeighborhoodIteratorType::OffsetType right = {{1,0}};

  ShapedNeighborhoodIteratorType::RadiusType radius;

  radius.Fill( 1 );

 

  typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<
ImageType > FaceCalculatorType;

  FaceCalculatorType faceCalculator;

  FaceCalculatorType::FaceListType faceList;

  FaceCalculatorType::FaceListType::iterator faceListIterator;

  faceList = faceCalculator( inputImage, inputImage->GetRequestedRegion(),
radius );

 

  for ( faceListIterator=faceList.begin(); faceListIterator !=
faceList.end(); ++faceListIterator)

  {

    std::cout << "Face group" << std::endl;

 

    ShapedNeighborhoodIteratorType it( radius, reader->GetOutput(),
*faceListIterator );

 

    for (it.GoToBegin(); !it.IsAtEnd(); ++it)

    {

      std::cout << "Centre index: " << it.GetIndex() << std::endl;

 

      it.ActivateOffset(top);

      it.ActivateOffset(bottom);

      it.ActivateOffset(left);

      it.ActivateOffset(right);

 

      ShapedNeighborhoodIteratorType::ConstIterator ci;

 

      std::cout << "  Neighbor values: ";

      for (ci = it.Begin(); ci != it.End(); ci++)

      {

        std::cout << ci.Get() << " "; // All neighbors visited?!?, How to
GetIndex() ?!?

      }

      std::cout << std::endl;

    }

  }


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


More information about the Insight-users mailing list