[ITK-users] Neighborhood Iterators moving at constant intervals
Abu-Sammour, Denis
Denis.Abu-Sammour at medma.uni-heidelberg.de
Fri May 29 05:23:34 EDT 2015
Hello Matt,
Thanks for your reply.
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
-----Ursprüngliche Nachricht-----
Von: Matt McCormick [mailto:matt.mccormick at kitware.com]
Gesendet: Donnerstag, 28. Mai 2015 18:29
An: Abu-Sammour, Denis
Cc: insight-users at itk.org
Betreff: Re: [ITK-users] Neighborhood Iterators Starting and Ending point
Hi Denis,
Depending on your goals, working with a std::slice on the neighborhood may help or just defining the neighborhood over the desired region could be an alternative. The documentation on NeighborhoodIterators may help [1].
HTH,
Matt
[1] http://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch6.html#x47-1110006.4
On Tue, May 26, 2015 at 12:00 PM, Abu-Sammour, Denis <Denis.Abu-Sammour at medma.uni-heidelberg.de> wrote:
> Hello,
>
> Is there a way to force the neighborhood iterator to start iterating
> in a defined point rather than using GoToBegin() which moves the
> center of the neighborhood iterator to the 1st pixel in the iteration
> region? For example, is it possible to start iterating (i.e. the 1st
> neighborhood is centered) at say (x=5,y=5) with a neighborhood radius
> of 5 pixels then move with a step (offset) of 10 pixels stopping the
> iteration at (x= end – 5, y= end –
> 5) rather than IsAtEnd() ?
>
> Thank you.
>
> Denis
>
>
> _____________________________________
> 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.php
>
> 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://public.kitware.com/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list