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

David Doria daviddoria at gmail.com
Mon Mar 21 16:18:50 EDT 2011


On Mon, Mar 21, 2011 at 10:32 AM, Hugues Fontenelle <
hugues.fontenelle at rr-research.no> wrote:

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

Hugues,

Great! I'm glad you figured it out. We certainly appreciate you reporting
back as you did so that others with the same problem will have somewhere to
start. As for being "afraid of messing up" the wiki - don't be! It keeps an
infinite revision history so if you really break something we can always go
back to a previous version. In this case, I think your addition is worth
adding a new example rather than revising an old one. Maybe something like
"NeighborhoodIteratorWithBoundaryCondition" or similar. If you want to, give
it a shot! If you have any questions or concerns don't hesitate to let me
know. Having this set of examples maintained by everyone is critical to its
success!

Thanks,

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


More information about the Insight-users mailing list