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

Matt McCormick matt.mccormick at kitware.com
Mon Dec 5 11:03:52 EST 2011


Hi Anna,

You want to look at how ImageBoundaryFacesCalculator is used:

http://www.itk.org/Doxygen/html/structitk_1_1NeighborhoodAlgorithm_1_1ImageBoundaryFacesCalculator.html

Create one, then only iterate on region 0.

Matt

On Mon, Dec 5, 2011 at 10:57 AM, anna han wan <anna.han.wan at gmail.com> wrote:
> 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;
>
>             }
>
>
>
>       }
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list