I did slice extraction once. The code was posted on this list some months ago. Take a look there.<br><br>You should set input image once, before the loops. You should not call disconnect at all.<br>In loops, call setExtractionRegion, update and getOutput.<div>

<br>In the code excerpt you provided, you never initialize the variable gsquare_size. It should be initialized before the loops, if it is not already so.</div><div><br></div><div>I didn&#39;t know before that there exist &quot;<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">UpdateLargestPossibleRegion&quot; :D</span><br>

<div><font class="Apple-style-span" face="verdana, sans-serif"><br></font><div class="gmail_quote">On Tue, Aug 9, 2011 at 19:48, Kevin Zhang <span dir="ltr">&lt;<a href="mailto:zhangk@uchicago.edu">zhangk@uchicago.edu</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello all,<br>
<br>
I am attempting to implement a grid-based thresholding algorithm over a 3D image volume. I am trying to use ExtractImageFilter to extract 2D square subregions from each slice in the volume. Code is as follows:<br>
<br>
ExtractFilterType::Pointer ExtractSquareFilter = ExtractFilterType::New();<br>
    for(unsigned int i = 0; i &lt; numslices; i++)<br>
    {<br>
        // extract grid square, iterating across row and column of slice<br>
        for(unsigned int sr = 0; sr &lt; num; sr++)<br>
        {<br>
            for(unsigned int sc = 0; sc &lt; num; sc++)<br>
            {<br>
                FloatImageType::RegionType gsquare_region;<br>
                FloatImageType::RegionType::<u></u>IndexType gsquare_index;<br>
                gsquare_index[0] = sc * sidelength;<br>
                gsquare_index[1] = sr * sidelength;<br>
                gsquare_index[2] = i; // set slice<br>
                gsquare_region.SetSize(<u></u>gsquare_size);<br>
                gsquare_region.SetIndex(<u></u>gsquare_index);<br>
                ExtractSquareFilter-&gt;SetInput(<u></u>inputimg);<br>
               ExtractSquareFilter-&gt;<u></u>SetExtractionRegion(gsquare_<u></u>region);<br>
                ExtractSquareFilter-&gt;<u></u>UpdateLargestPossibleRegion();<br>
                Float2DImageType::Pointer square = ExtractSquareFilter-&gt;<u></u>GetOutput();<br>
                square-&gt;DisconnectPipeline();<br>
                std::cerr &lt;&lt; &quot;Grid square extracted successfully&quot; &lt;&lt; std::endl;<br>
<br>
The input dataset is a series of 128x128 images. I am currently trying to divide each slice into a 4x4 grid, where each square would be 32x32.<br>
<br>
The errors I get when executing are:<br>
itkImageConstIteratorWithIndex<u></u>.txx:90: itk::<u></u>ImageConstIteratorWithIndex&lt;<u></u>TImage&gt;::<u></u>ImageConstIteratorWithIndex(<u></u>const TImage*, const typename TImage::RegionType&amp;) [with TImage = itk::OrientedImage&lt;float, 2u&gt;]: Assertion `Region ImageRegion (0xbf7ff6ec)<br>


  Dimension: 2<br>
  Index: [0, 0]<br>
  Size: [32, 32]<br>
 is outside of buffered region ImageRegion (0x97d3680)<br>
  Dimension: 2<br>
  Index: [32, 0]<br>
  Size: [32, 32]<br>
&#39; failed.<br>
<br>
I have tried several things to fix this, including:<br>
1. Instantiate the ExtractImageFilter inside the loop<br>
2. Use UpdateLargestPossibleRegion() instead of Update() on ExtractImageFilter<br>
<br>
Thanks in advance for any insights! No pun intended.)<br>
<br>
Kevin Zhang<br>
Student Research Assistant<br>
Department of Radiology / Cancer Research Center<br>
University of Chicago<br>
<br>
______________________________<u></u>_______<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/<u></u>products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/<u></u>listinfo/insight-users</a><br>
</blockquote></div><br></div></div>