[Insight-users] Help with moving NeighborhoodIterator with an offset

anna han wan anna.han.wan at gmail.com
Mon Dec 5 10:57:51 EST 2011


Hi all,

I am using NeighborhoodIterator to visit all voxels of my image(3D) and to
do some processing within a rectangular neighborhood. As doing this is a
time consuming process, I decided to move the iterator with an offset
rather than visiting every voxel. When I run my code I got the following
error:



Unhandled exception at 0x000007fefcceaa7d in main.exe: Microsoft C++
exception: itk::ExceptionObject at memory location 0x00b4f4a8.



This is because the iterator has reached the image border. So my question
is how can I increment the ierator with an offset and check at the same
time if I reched the image border?  I find the function InBounds but I
don’t know how to use it properly?









The relevent part of my code that the error is related to is as follows:



typedef itk::NeighborhoodIterator<ImageType> NeighborhoodIteratorType;

NeighborhoodIteratorType It(radius, image,region);

It.NeedToUseBoundaryConditionOff();



NeighborhoodIteratorType::OffsetType ItOffset;

ItOffset.Fill(2);





      for ( It.GoToBegin(); !It.IsAtEnd();  It += ItOffset)

      {



            sum=0;

            for(i = 0; i < It.Size(); i++)

            {

              if (It.GetPixel(i)>0)

                    sum=sum+1;

            }



      }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111205/f93a63d2/attachment.htm>


More information about the Insight-users mailing list