[Insight-users] ShapedNeighborhoodIterator: how to get indexes and how to check bounds?
Hugues Fontenelle
hugues.fontenelle at rr-research.no
Thu Mar 17 11:24:50 EDT 2011
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/20110317/8c141842/attachment.htm>
More information about the Insight-users
mailing list