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

anna han wan anna.han.wan at gmail.com
Tue Dec 6 06:36:17 EST 2011


Thanks all for your relpy.

I tried to resolve my problem but I find that I was digging in the wrong
way.

What I want to do is something like the traditional image increment process
:

// image (DimX,DimY,DimZ)

for(int i=0; i<DimX; i=i+Stepx)

for(int j=0; j<DimY; i=j+Stepy)

for(int k=0; k<DimZ; i=k+Stepz)

{

Process the image at location (i,j,k)

}

Moving the neighbourhood iterator  with an offset as in the loop  (
It.GoToBegin(); !It.IsAtEnd();  It += ItOffset) does increment the iterator
in the three direction (X,Y,Z) AT THE SAME TIME but what I am looking for
is incrementing the iterator as the above loop (dimension by dimension).

I explain again my goal which is to compute some measures within the
neighbourhood of image voxels. Neighbourhood iterator is good option but
the problem is it is very very slow (it could take 1 hour or even more to
process one image).  So to speed up this process I decided to compute the
measures in only some location rather than doing this for every voxel.

Thank all for your time and help.


On Mon, Dec 5, 2011 at 4:03 PM, Matt McCormick
<matt.mccormick at kitware.com>wrote:

> 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
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20111206/c0170377/attachment.htm>


More information about the Insight-users mailing list