<br>Hi Mengda,<br><br>The best way, is of course, to run a set of tests,<br>comparing the different computation times.<br><br>You can use the TimeProbe classes in order<br>to measure computation times.<br><br>My guess is that option (2) will be faster than<br>
option (1), but not by much.<br><br><br><br>Looking at the source code will give you an<br>initial idea of what is involved.<br><br>See the file:<br><br>ITK/Code/Common/itkImageConstIterator.h<br><br>lines 227-237:<br><br>
void SetIndex(const IndexType & ind)<br> {<br> m_Position = m_Image->GetBufferPointer() + m_Image->ComputeOffset(ind);<br> m_PositionIndex = ind;<br> }<br><br><br> PixelType Get(void) const<br> { return m_PixelAccessorFunctor.Get(*m_Position); }<br>
<br><br>and compare this, <br>with the code of the file:<br><br> ITK/Code/Common/itkImage.h<br><br>lines 209-213:<br><br> const TPixel & GetPixel(const IndexType & index) const<br> {<br> typename Superclass::OffsetValueType offset = this->ComputeOffset(index);<br>
return ( ( *m_Buffer )[offset] );<br> }<br><br><br><br>It seems that using (2) will be slightly more direct.<br><br><br> Regards,<br><br><br> Luis<br><br><br><br><br>-----------------------------------------------------------------------<br>
<div class="gmail_quote">On Thu, Oct 21, 2010 at 3:21 PM, Mengda Wu <span dir="ltr"><<a href="mailto:wumengda@gmail.com">wumengda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi all,<br><br> I am trying to compare the efficiency of different options to access pixel values in ITK image. I understand if it is<br>a serial access (from begin to end), the iterator is the best choice. But what if I would like to access one arbitrary<br>
pixel at a time. What would be more efficient?<br> <br> (1) Use iterator->SetIndex(ind) and then iterator->Get() or iterator->Set();<br> (2) Use image->GetPixel(ind) or image->SetPixel(ind);<br> (3) or something else<br>
<br>Thanks,<br><font color="#888888">Mengda<br><br>
</font><br></blockquote></div>