[Insight-users] more efficient way to set pixels than SetPixel() and GetPixel() from RGBImage

David Doria daviddoria at gmail.com
Fri Feb 10 06:04:32 EST 2012


On Thu, Feb 9, 2012 at 9:52 PM, cagatay bilgin <bilgincc at gmail.com> wrote:
> Hi Daniel,
>
> You would want to use iterators instead of SetPixel
> and GetPixel. Chapter 11 of the itk manual explains
> how to use them. Also, a simple example is given here
>
> http://www.vtk.org/Wiki/ITK/Examples/Iterators/ImageRegionIterator
>
> Regards,
> Cagatay

The basic iterator loop is:

  itk::ImageRegionIterator<ImageType> imageIterator(image,region);

  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(255);
    PixelType p = imageIterator.Get();
    // With some iterators (ones with WithIndex in the name), you can do:
    ImageType::IndexType ind = imageIterator.GetIndex();
    ++imageIterator;
    }

See also:

http://www.itk.org/Wiki/ITK/Examples/Iterators/ImageRegionIterator
http://www.itk.org/Wiki/ITK/Examples/Iterators/ImageRegionIteratorWithIndex

David


More information about the Insight-users mailing list