[Insight-users] ShapedNeighborhoodIterator: how to get indexes and how to check bounds?
Hugues Fontenelle
hugues.fontenelle at rr-research.no
Mon Mar 21 10:32:04 EDT 2011
Dear Insight Users,
Thank you Dawood and David,
Re-reading the material that you advised was useful, and I can now rephrase
my question correctly:
"How do I set up boundary conditions for neighbor iterators?"
I did find the answer though! I thought that it would be useful to post it
here. Perhaps the example codes can be updated? I'm a bit afraid of messing
that up so I leave it to you. In the meantime here is the tricks.
By default, the boundary conditions are set to Neumann, i.e. the first
derivative across the boundary is zero.
However there are cases where you want a constant boundary, i.e. pad the
image with zeros. Then the iterator type should be :
typedef itk::ConstantBoundaryCondition< ImageType > BoundaryConditionType;
typedef itk::ShapedNeighborhoodIterator< ImageType, BoundaryConditionType
> ShapedNeighborhoodIteratorType;
Now out-of-bounds pixels will return zero.
For another constant value (such as -1) I use the following:
typedef itk::ConstantBoundaryCondition< ImageType > BoundaryConditionType;
BoundaryConditionType BoundaryCondition ;
BoundaryCondition.SetConstant( -1 );
And later apply it the neighbor iterator:
it.OverrideBoundaryCondition(&BoundaryCondition);
I hope it helps someone else.
Regards
Hugues.
From: Dawood Masslawi [mailto:masslawi at gmail.com]
Sent: Saturday, 19 March, 2011 14:25
To: hugues.fontenelle at rr-research.no
Cc: insight-users at itk.org
Subject: RE: ShapedNeighborhoodIterator: how to get indexes and how to check
bounds?
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_1ImageB
oundaryFacesCalculator.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/20110321/2e62dac6/attachment-0001.htm>
More information about the Insight-users
mailing list