[Insight-users] how to modify regions with iterators

Koen Vermeer koen at vermeer.tv
Wed Dec 1 15:09:47 EST 2010


On Wed, 2010-12-01 at 12:25 -0500, David Doria wrote:
> > I'm trying to modify some image in a very basic way, the idea is
> > image (x>10)=0
> > so all the values of the image which x component is bigger than 10 are set
> > to 0.
> > I don't find very obvious to do it with itk iterators... any leads?? maybe
> > some filter?
> You'll want to modify the iterator loop to look like:
>   while(!imageIterator.IsAtEnd())
>     {
>     if(imageIterator.GetIndex()[0] > 10)
>       {
>       imageIterator.Set(0);
>       }
>     ++imageIterator;
>     }

I don't think that's what he wants. I'm not that experienced with ITK,
so I cannot produce working code just like that, but you'll need two
iterators. One of them will iterate over x (and can be a ConstIterator,
or something like that) and the other will iterate over image. Something
like:

while(!imageIterator.IsAtEnd())
    {
    if xConstIterator.Get()>10
        {
        imageIterator.Set(0)
        }
    ++imageIterator;
    ++xConstIterator;
    }

Not sure if there are any filters that allow you to do this efficiently.
I always have a hard time finding the filters that I need, which
actually prevents me from using ITK more often than I do now...

Best,
Koen




More information about the Insight-users mailing list