[Insight-users] Efficiency in arbitrarily accessing pixel values in ITK image

Luis Ibanez luis.ibanez at kitware.com
Sun Oct 31 10:16:32 EDT 2010


Hi Mengda,

The best way, is of course, to run a set of tests,
comparing the different computation times.

You can use the TimeProbe classes in order
to measure computation times.

My guess is that option (2) will be faster than
option (1), but not by much.



Looking at the source code will give you an
initial idea of what is involved.

See the file:

ITK/Code/Common/itkImageConstIterator.h

lines 227-237:

  void SetIndex(const IndexType & ind)
  {
    m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);
    m_PositionIndex = ind;
  }


  PixelType Get(void) const
  { return m_PixelAccessorFunctor.Get(*m_Position); }


and compare this,
with the code of the file:

          ITK/Code/Common/itkImage.h

lines 209-213:

  const TPixel & GetPixel(const IndexType & index) const
  {
    typename Superclass::OffsetValueType offset =
this->ComputeOffset(index);
    return ( ( *m_Buffer )[offset] );
  }



It seems that using (2) will be slightly more direct.


  Regards,


         Luis




-----------------------------------------------------------------------
On Thu, Oct 21, 2010 at 3:21 PM, Mengda Wu <wumengda at gmail.com> wrote:

> Hi all,
>
>    I am trying to compare the efficiency of different options to access
> pixel values in ITK image. I understand if it is
> a serial access (from begin to end), the iterator is the best choice. But
> what if I would like to access one arbitrary
> pixel at a time. What would be more efficient?
>
>    (1) Use iterator->SetIndex(ind) and then iterator->Get() or
> iterator->Set();
>    (2) Use image->GetPixel(ind) or image->SetPixel(ind);
>    (3) or something else
>
> Thanks,
> Mengda
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101031/c38d169e/attachment.htm>


More information about the Insight-users mailing list