[Insight-users] Iterate on image columns

Luis Ibanez luis.ibanez at kitware.com
Wed Oct 10 08:57:14 EDT 2007


Hi Emmanuel,

Thanks for letting us know about the context of your problem.

Here are some comments, (not in the same order as your email)

1) The Direction in the ImageBase class doesn't refer to the
    memory arrangement of pixel data in memory. Instead it refers
    to the physical orientation of the image in space. It is a
    matrix containing the direction cosines of vectors aligned with
    the axis of the image grid. They orient the image grid in the
    context of the coordinate system of the image acquisition device
    (e.g. CT Scanner, MRI, microscope, satellite...)

2) The main trade-off between the iterators "WithIndex" and the basic
    ImageRegionIterator is that the iterators with index internally
    keep an updated "index" with the current pixel position. By doing
    this, they consume extra time in the task of updating that index,
    but they respond faster than the ImageRegionIterator if you ask
    for the index.  The rule of thumb is that:

    if your for-loop queries the index of the iterator, then you have
    better performance by using the "iterator with index". Otherwise,
    you have better performance by using the basic ImageRegionIterator.


3) Yes, it could be possible to include the NextLine() and
    IsAtEndOfLine() as part of the operator++() call.

    However, due to the backward compatibility policy, we can't do
    this in the current ImageSliceIteratorWithIndex. What we can do
    is to create a NEW iterator that has that behavior. That new
    iterator could reuse code (or derive) from the Slice iterator.
    The required code modifications are probably minimal. The hardest
    part will be to pick up a name for it  :-)

    We would strongly encourage you to create this new class and to
    submit it as a contribution to the Insight Journal, so that we
    can insert it into ITK in a future release.

    For details, please read
http://www.itk.org/Wiki/ITK_Procedure_for_Contributing_New_Classes_and_Algorithms

    Please let us know if you have problems creating this new class,
    we will be happy to help you in the process.


4) The Neighborhood iterator doesn't have multiple policies about how
    to walk along the image.

    This will require too to create a new class.  In this case the
    trick is that the Neighborhood iterator carries with it an array
    of pointers to the neighbors, and this array is updated at every
    call of the operator++(). When customizing the direction of walking
    along the image, we will have to customize the update to the pointers
    array accordingly.

    This also will be a good candidate for a submission to the
    Insight Journal. We could also propose it as a course project
    for a programming class.  :-)


   Regards,


      Luis



----------------------------
Emmanuel Christophe wrote:
> Hi Luis,
> 
> One of the motivation to use the itk::ImageSliceConstIteratorWithIndex
> was to benefit from the SetFirstDirection() and SetSecondDirection()
> functions.
> 
> I had an algorithm which was doing a processing privileging one
> direction on the image. The idea was to be able to do a
> SetDirection(1) on all iterators of the program to get the same
> algorithm privileging the other direction. This is when I first tried
> to replace the itk::ImageRegionIterator into
> itk::ImageSliceIteratorWithIndex and run into problems with the loops.
> 
> Wouldn't it be possible to include the NextLine() into the ++ and
> still have a working IsAtEndOfLine()?
> 
> Another solution to my problem would have been simply to transpose the
> image, but that wouldn't have been efficient in term of memory.
> 
> Anyway, I managed to go around my problem modifying the loops. What
> are the trade-off compared with the traditional
> itk::ImageRegionConstIterator?
> 
> I have seen that itk::ImageBase has a direction member. However, it
> does not seem to do what I was looking for: I tried to change it for
> an anti-diagonal matrix but it does not seem to influence iterators.
> 
> One thing I'm still looking for is a solution to introduce this
> transposition in directions in the itk::NeighborhoodIterator.
> 
> Regards,
> Emmanuel
> 
> 
> 2007/10/8, Luis Ibanez <luis.ibanez at kitware.com>:
> 
>>Hi Emmanuel,
>>
>>Yes, it could be possible to incorporate the IsAtEndOfSlice()
>>and IsAtEndOfLine() into the operator++, as well, as to
>>incorporate the NextLine() and NextSlice() calls.
>>
>>However, when we typically use this Iterator is because we
>>*need* to know when it reaches the end of line and when it
>>reaches the end of the slice. The reason is typically that
>>we are doing some extra processing between reaching the end
>>of the line and moving to the next line.
>>
>>Imagine for example the implementation of the FFT algorithm,
>>where we apply FFTs on every line. In that case, there are
>>extra processing to be inserted at the end of visiting each
>>line, e.g. to invoke that subroutines that actually compute
>>FFT.
>>
>>
>>-----
>>
>>
>>What is exactly the processing that you are performing in
>>the pixels ?
>>
>>and why are you looking for a particular row and column order
>>but you are not worry about knowing when you read the end of
>>the lines and the slices ?
>>
>>
>>   Please let us know,
>>
>>
>>      Thanks
>>
>>
>>         Luis
>>
>>
>>----------------------------
>>Emmanuel Christophe wrote:
>>
>>>Hi all,
>>>
>>>I was looking for an iterator flexible enough to go through an image
>>>line by line (as usual) but also column by column.
>>>
>>>I found the itk::ImageSliceConstIteratorWithIndex with the method
>>>SetFirstDirection() and SetSecondDirection() which exactly does that.
>>>
>>>However, when trying to use this iterator as usual:
>>>
>>>  while (!inputIterator.IsAtEnd())
>>>  {
>>>        inputIterator.Get();
>>>        ++inputIterator;
>>>  }
>>>
>>>I quickly ran into a segfault.
>>>
>>>It appears that this iterator has to be used in a slightly more complicated way:
>>>
>>>  while (!inputIterator.IsAtEnd())
>>>  {
>>>    while (!inputIterator.IsAtEndOfSlice())
>>>    {
>>>      while(!inputIterator.IsAtEndOfLine())
>>>      {
>>>        inputIterator.Get();
>>>        ++inputIterator;
>>>      }
>>>      inputIterator.NextLine();
>>>    }
>>>  inputIterator.NextSlice();
>>>  }
>>>
>>>Wouldn't it be possible to add the IsAtEndOfLine() and
>>>IsAtEndOfSlice() tests directly into the operator++ ?
>>>
>>>It wouldn't modify the overall complexity as the test has to be done
>>>anyway in the while loop.
>>>
>>>Regards,
>>>Emmanuel Christophe
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
> 


More information about the Insight-users mailing list