[Insight-users] Q about iterator (how to increase by specific steps)
Luis Ibanez
luis.ibanez at kitware.com
Mon May 28 17:35:53 EDT 2012
Hi Erkang,
Most of the Iterators in ITK are pre-set to
advance by one only.
You may find easier to implement this by
directly controlling the index, with code
such as:
SizeType size = region.GetSize();
IndexType index = region.GetIndex();
for (int z=0; z<size[2]; z+=step_z)
{
index[2] = z;
for (int y=0; y<size[1], y+step_y)
{
index[1] = y;
for(int x=0; x<size[0]; x+=step_x)
{
index[0] = x;
PixelType value = image->GetPixel( index );
// calculate response at (x,y,z)
}
}
}
The disadvantage is that this is not very fast
at run time... so, if you need something to
perform at high speed, it might be worth to
customize one of the existing Iterators, for
example the SliceIteratorWithIndex:
http://www.itk.org/Doxygen/html/classitk_1_1ImageSliceConstIteratorWithIndex.html
The modifications may not be trivial though....
Yet another option is to simply use the ShrinkImageFilter,
http://www.itk.org/Doxygen/html/classitk_1_1ShrinkImageFilter.html
to first sub-sample the image by the steps that you
want to use in X,Y and Z, and then use a standard
iterator on the sub-sampled image.
Luis
------------------------------------------------------
On Wed, May 23, 2012 at 4:17 PM, Erkang Cheng <ekyaya at gmail.com> wrote:
> Hi everyone:
>
> I want to loop over the image domain by increasing specific steps along
> each direction.
>
> Which iterator is appropriated for my case?
>
> I want to realize the following nest loop:
>
> The image size is size_x, size_y, size_z;
>
> And the steps I want to increase are: step_x, step_y, step_z;
>
> for (int z=0; z<size_z; z+=step_z)
> for (int y=0; y<size_y, y+step_y)
> for(int x=0; x<size_x; x+=step_x)
> {
> // calculate response at (x,y,z)
> }
>
> Is there similar example for me to follow? Thanks.
>
> Best
> Erkang
>
> _____________________________________
> 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://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120528/c3a7979b/attachment.htm>
More information about the Insight-users
mailing list