Check out the ShapedNeighborhoodIterator class. I have not used it before, but the description sounds like it may work. You can set the neighborhood pixels to iterate by adding the offsets to an active list.<div><div><div>
<br><div class="gmail_quote">On Wed, Feb 16, 2011 at 1:13 PM, Jiao Lin <span dir="ltr">&lt;<a href="mailto:jiao.lin@gmail.com">jiao.lin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Robert,<br>
<br>
Thanks for your quick response! That is certainly a solution. But the<br>
SetLocation method is not optimized for speed so I wonder if there is<br>
a better way to do it.<br>
<br>
--Jiao<br>
<div><div></div><div class="h5"><br>
On Wed, Feb 16, 2011 at 10:11 AM, robert tamburo<br>
&lt;<a href="mailto:robert.tamburo@gmail.com">robert.tamburo@gmail.com</a>&gt; wrote:<br>
&gt; As you iterate the image, check to see if you&#39;re on the grid. If you are,<br>
&gt; then set and iterate the neighborhood. Something like:<br>
&gt; while(!it.IsAtEnd())<br>
&gt;   {<br>
&gt;   index = it.GetIndex();<br>
&gt;   if( (index[0] % 2 == 0) &amp;&amp; (index[1] % 3 == 0) )  // or whatever<br>
&gt;     {<br>
&gt;     neighborhoodIt.SetLocation(index);<br>
&gt;     // iterateTheNeighborhood<br>
&gt;     .<br>
&gt;     .<br>
&gt;     .<br>
&gt;     }<br>
&gt;   ++it;<br>
&gt;   }<br>
&gt;<br>
&gt; On Wed, Feb 16, 2011 at 12:40 PM, linjiao &lt;<a href="mailto:jiao.lin@gmail.com">jiao.lin@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Have a question regarding neighborhood iterator. My understanding is that<br>
&gt;&gt; after creating a neighborhood iterator, one can move the center of a<br>
&gt;&gt; neighborhood around an image region by increment the iterator:<br>
&gt;&gt;<br>
&gt;&gt; while (!it.IsAtEnd()) {<br>
&gt;&gt;  ...<br>
&gt;&gt;  ++it;<br>
&gt;&gt; }<br>
&gt;&gt;<br>
&gt;&gt; Each increment will bring the center to the next pixel in the image<br>
&gt;&gt; region.<br>
&gt;&gt; I am now wondering if it is possible to define a &quot;grid&quot; in the image<br>
&gt;&gt; region,<br>
&gt;&gt; and only let the center to move to the next pixel in that grid.<br>
&gt;&gt;<br>
&gt;&gt; So for example, we have a 10X10 image, right now we can define a<br>
&gt;&gt; neighborhood iterator whose center walks like this<br>
&gt;&gt;<br>
&gt;&gt; (0,0), (1,0), (2,0), .... (9,0), (0,1), (1,1) ....<br>
&gt;&gt;<br>
&gt;&gt; I am wondering if we can define a neighborhood iterator whose center walks<br>
&gt;&gt; in 2 steps in x direction, and 3 steps in y direction<br>
&gt;&gt;<br>
&gt;&gt; (0,0), (2,0), (4,0), ... (8,0), (0,3), (2,3), (4,3), ...<br>
&gt;&gt;<br>
&gt;&gt; Any hints are very appreciated.<br>
&gt;&gt;<br>
&gt;&gt; --Jiao<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&gt;&gt; <a href="http://old.nabble.com/neighborhood-iterator-tp30936654p30936654.html" target="_blank">http://old.nabble.com/neighborhood-iterator-tp30936654p30936654.html</a><br>
&gt;&gt; Sent from the ITK - Users mailing list archive at Nabble.com.<br>
&gt;&gt;<br>
&gt;&gt; _____________________________________<br>
&gt;&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;&gt;<br>
&gt;&gt; Visit other Kitware open-source projects at<br>
&gt;&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt;<br>
&gt;&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt;&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;&gt;<br>
&gt;&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt;&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;&gt;<br>
&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div></div></div>