[ITK-users] Neighborhood Iterators moving at intervals

Abu-Sammour, Denis Denis.Abu-Sammour at medma.uni-heidelberg.de
Fri Jun 12 03:07:15 EDT 2015


Hello,

Thanks for your time in advance.

So what I am trying to do is to iterate through the region of the image with a neighborhood iterator but instead of letting the center pixel of the neighborhood iterator visit all image pixels I want it sort of jump to pixels spaced at constant intervals. So say I force the Neighborhood iterator to start at pixel (10,10) by using " Iterator.SetLocation() " and assuming a constant step of 10,  how can I force the neighborhood iterator to jump to pixel (20,10) for the 2nd iteration then to pixel (30,10) at the 3rd iteration and so on.. ?

I tried defining an Offset " itk::Offset <2> BlockOffset " such that " BlockOffset[0] = 10 " and "  BlockOffset[1] = 10 ". Plugging that into the Neighborhood Iterator for loop " BlockIterator += (BlockOffset) " I found out that the neighborhood will jump in a diagonal manner through the image. Afterwards, I redefined " BlockOffset[0] = 10 " while "  BlockOffset[1] = 0 ", the iterator moved as planned in the x-direction jumping at regular steps of 10 pixels as needed however, it did not move to the next row of the image i.e. the neighborhood iterator kept moving in the x-direction even after exceeding the image x-dimension until a RunTime error occurred!

I tried to introduce " NeedToUseBoundaryConditionOn() " and a Face Calculator " itk::ImageBoundaryFacesCalculator "  with no success. Please note the region supplied to the iterator is well defined ( as a OutputImage->GetLargestPossibleRegion() ) and the problem did not occur when I used the regular Neighborhood Iterator which starts at " BlockIterator.GoToBegin() " and  incremented 1 pixel at a time (BlockIterator++). It appears that the Neighborhood iterator algorithm moves to the next row only if it encounters the pixel that is just outside the required region, therefore, when jumping at particular steps this pixel is almost never visited instead the iterator jumps to a pixel that is some distance outside the requested region and thus it does not go to the next row.

So far I was forced to use the latter approach (starting at the 1st pixel in the image and incrementing by 1 pixel at each neighborhood iteration) with Getting the Image Index of the center of the Neighborhood iterator at the current iteration, checking wither it is at the desired location, and proceeding with computations if it is the case:

for (BlockIterator.GoToBegin(); !BlockIterator.IsAtEnd(); BlockIterator++) {
        BlockCenter = BlockIt.GetIndex();

        if (BlockCenter[0] % StepSize == 0    &&    BlockCenter[1] % StepSize == 0    &&    BlockCenter[0] != 0    &&     BlockCenter[1] != 0)
        {
                //Proceed with computations
        }
}

 However, this approach is hardly efficient.   Please Advise.

Regards

Denis


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150612/38131ae2/attachment.html>


More information about the Insight-users mailing list