[Insight-users] creating custom iterators
Rémi Blanc
rblanc33 at gmail.com
Tue Sep 20 05:12:31 EDT 2011
Hi all,
I am seeking some help on iterators.
I am working on a project involving drawing shapes in an image. The
application works in such a way that first, for each shape, a stencil
image is generated (smallest box containing the shape), and then
inserted within an image.
Depending on the user choice, I want to be able to manage different
types of boundary conditions, including periodic boundary conditions
(taking the part of the shape that would normally be outside the image,
and drawing it at the other side of the image).
I started looking at the ShapedNeighborhood iterators, but have troubles
with them, and am not 100% sure if they are the way to go:
- my attempts to use periodic boundary conditions lead to a crash any
time I go outside the bounds, while keeping the default ZeroFluxBC works
(see explanations at the end of the mail).
- it seems the ShapedNeighborhood needs to be instanciated together with
the region where it should be applied, while in my view, I would first
need to learn the patterns of background pixels before caring about
where to apply the stencil.
-> I don't understand in the manual, section "Shaped neighborhoods:
morphological operations" why the structuring element is (needs to be?)
re-defined for each 'face'
- I am actually not interested in iterating over the whole image with
the neighborhood iterator as in a mathematical morphology filter, but
only to 'apply' the stencil at a handful locations at most.
I would like to do the following thing:
Typically, even in the smallest rectangular box, some pixels/voxels
correspond to background.
Since I may draw the same shape at different places in the image (using
translations of integer grid spacing), I would like to code that some
voxels of the stencil are just background and avoid iterating through them.
As I mentionned, I would also be able to manage different types of
boundary conditions efficiently.
=> I need a way to circulate efficiently and simultaneously in the
stencil and the image in the image (avoiding the background pixels from
the stencil) while additionnally managing the boundary conditions in the
image if necessary.
While I am here... I would also like to generate a second iterator, this
time over the image. The goal here would be to remember which pixels of
the image have been modified when applying stencils (possibly several of
them, overlapping, etc...) , so that I don't need to scan the whole
image to update the next steps of my programs (=> actually, the
application of stencils is subject to an optimization procedure ;
re-scanning the whole image while only a small part of it has changed is
a serious bottelneck, which is actually not necessary in my case to
update the metric).
Did I miss existing functionalities that could help doing this?
Any hints would be much appreciated,
Thanks a lot,
Rémi
Concerning the crash using periodic boundary conditions and ShapedNeighborhood, I started from the wiki example ShapedNeighborhoodIterator_Manual.cxx
Replacing :
typedef itk::ShapedNeighborhoodIterator<ImageType> IteratorType;
by
typedef itk::ZeroFluxNeumannBoundaryCondition<ImageType> ZFBCType;
typedef itk::ShapedNeighborhoodIterator<ImageType, ZFBCType> IteratorType;
the example executes
However, when using
typedef itk::PeriodicBoundaryCondition<ImageType> PBCType;
typedef itk::ShapedNeighborhoodIterator<ImageType,PBCType> IteratorType;
instead, the program crashes at the first call to ci.GetNeighborhoodIndex()
More information about the Insight-users
mailing list