<div dir="ltr"><div><div><div><div>Hi Brad,<br><br>Thank you for the suggestion!<br><br></div>Sorry in my previous code I had the mistake for randomly picking position for the center point. Now I changed it to be in the inner region.<br>
index[0] = rg.lrand32(1, size[0] - 2);<br>index[1] = rg.lrand32(1, size[1] - 2);<br>index[2] = rg.lrand32(1, size[2] - 2);<br><br></div>And I also turn off the boundary condition by:<br>it.NeedToUseBoundaryConditionOff();<br>
<br></div>Now with the same parameters, nbhditerator is around 4 seconds (vs direct access 5.5 seconds)!<br><br></div>I will modify my code to take advantage of this! <br><br>Thank you!<br><div><br>Best,<br>yi<br><div><div>
<br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 13, 2013 at 11:34 AM, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<div class="im"><br>
On May 13, 2013, at 11:03 AM, &quot;Gao, Yi&quot; &lt;<a href="mailto:gaoyi.cn@gmail.com">gaoyi.cn@gmail.com</a>&gt; wrote:<br>
&gt; When using NeighborhoodIterator, i&#39;m not sure if the boundary checking is automatically turned on. I guess if that is by default on, then there is not much speed gain with it.<br>
<br>
<br>
</div>Because the region you specify to the Iterator is on the boundary it will turn on the boundary checking. You can either turn off the condition:<br>
<br>
<a href="http://www.itk.org/Doxygen/html/classitk_1_1ConstNeighborhoodIterator.html#a438cb0146b802b04a771a2461952cff8" target="_blank">http://www.itk.org/Doxygen/html/classitk_1_1ConstNeighborhoodIterator.html#a438cb0146b802b04a771a2461952cff8</a><br>

<br>
or you can change the region size you initialize the Iterator with.<br>
<br>
You can just use the operator&lt;&lt; to check what the iterator is doing.<br>
<br>
Also consider using a large type for the accumulation type, such as itk::NumericTraits&lt;T&gt;::AccumulatorType;<br>
<br>
And consider using std::accumulate(it.Begin(), it.End(), 0 )<br>
<br>
Brad</blockquote></div><br></div>