Robert,<br><br>When you update the ExtractImageFilter, you should call UpdateLargestPossibleRegion() instead of <br>calling Update(). When a region is changed, there is a possibility that the data cached in pipeline<br>may not be valid.&nbsp; This is what the exception is reporting.&nbsp; A call to UpdateLargestPossibleRegion()
<br>tells the pipeline to ignore any cached region sizes.<br><br>Jim<br><br><br><br><div><span class="gmail_quote">On 6/5/06, <b class="gmail_sendername">Atwood, Robert C</b> &lt;<a href="mailto:r.atwood@imperial.ac.uk">r.atwood@imperial.ac.uk
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Hi,<br>I am trying to obtain the statistics for some specified regions of an
<br>image (eventualy each of several images)<br> I seem to be getting an exception thrown the second time I try to<br>extract a region. Is there something that needs to be done to reset the<br>extractImagefilter?<br><br>In this case I defined the pixel type to unsigned short and the input
<br>image is 1015x512. With this example the size of the region is 20x20 and<br>the index starts at 0,200 and increases by 5,0 until 20,200 so there<br>should be lots of room in the image for the region.<br><br><br><br>Thanks,
<br>Robert<br><br>*****Some output ********************<br><br>...reading<br>Region One: ImageRegion (0x7fbfffde70)<br>&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [0, 0]<br>&nbsp;&nbsp;Size: [1015, 512]<br><br>Region Two: ImageRegion (0x602118)<br>
&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [0, 0]<br>&nbsp;&nbsp;Size: [1015, 512]<br><br>Region Three: ImageRegion (0x7fbfffde70)<br>&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [0, 200]<br>&nbsp;&nbsp;Size: [20, 20]<br><br>Region Four: ImageRegion (0x602118)<br>&nbsp;&nbsp;Dimension: 2
<br>&nbsp;&nbsp;Index: [0, 0]<br>&nbsp;&nbsp;Size: [1015, 512]<br><br>Sample mean = [18226.6]<br>Region Two: ImageRegion (0x602118)<br>&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [0, 0]<br>&nbsp;&nbsp;Size: [1015, 512]<br><br>Region Three: ImageRegion (0x7fbfffde70)<br>
&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [5, 200]<br>&nbsp;&nbsp;Size: [20, 20]<br><br>Exception caught chopper update !<br><br>itk::InvalidRequestedRegionError (0x614500)<br>Location: &quot;virtual void itk::DataObject::PropagateRequestedRegion()&quot;
<br>File: /sources/local/ITK_cvs/Code/Common/itkDataObject.cxx<br>Line: 397<br>Description: Requested region is (at least partially) outside the<br>largest possible region.<br><br><br>Region Four: ImageRegion (0x602118)<br>
&nbsp;&nbsp;Dimension: 2<br>&nbsp;&nbsp;Index: [0, 0]<br>&nbsp;&nbsp;Size: [1015, 512]<br><br>Sample mean = [18226.6]<br><br><br><br><br>****************** The Code *************************************<br><br>#include &lt;stdio.h&gt;<br><br>#include &quot;
itkImage.h&quot;<br>#include &quot;itkImageFileReader.h&quot;<br>#include &quot;itkScalarImageToListAdaptor.h&quot;<br>#include &quot;itkScalarToArrayCastImageFilter.h&quot;<br>#include &quot;itkMeanCalculator.h&quot;<br>
#include &quot;itkExtractImageFilter.h&quot;<br>#include &quot;itkRegionOfInterestImageFilter.h&quot;<br><br>#ifdef T_FLOAT<br>&nbsp;&nbsp;typedef float PixelType;<br>#elif defined T_BYTE<br>&nbsp;&nbsp;typedef unsigned char PixelType;<br>#elif defined T_USHORT
<br>&nbsp;&nbsp;typedef unsigned short PixelType;<br>#elif defined T_UINT<br>&nbsp;&nbsp;typedef u_int32_t PixelType;<br>#else<br>#warning NO TYPE DEFINED, defaulting to FLOAT<br>&nbsp;&nbsp;typedef float PixelType;<br>#endif<br><br><br>&nbsp;&nbsp;typedef itk::Image&lt; PixelType, 2 &gt; ImageType;
<br><br>&nbsp;&nbsp;// definitions for writing the image<br>&nbsp;&nbsp;typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;<br>&nbsp;&nbsp;typedef itk::FixedArray&lt; PixelType, 1 &gt; MeasurementVectorType;<br>&nbsp;&nbsp;typedef itk::Image&lt; MeasurementVectorType, 2 &gt; ArrayImageType;
<br>&nbsp;&nbsp;typedef itk::Statistics::ScalarImageToListAdaptor&lt; ImageType &gt;<br>SampleType;<br>&nbsp;&nbsp;typedef itk::Statistics::MeanCalculator&lt; SampleType &gt;<br>MeanAlgorithmType;<br>&nbsp;&nbsp;typedef itk::ExtractImageFilter&lt;ImageType,ImageType&gt; ChopperType;
<br>/*********************************/<br>/* beginning of MAIN routine&nbsp;&nbsp;&nbsp;&nbsp; */<br>/*********************************/<br>int main(int argc, char ** argv) {<br>&nbsp;&nbsp;int i,j;<br><br>&nbsp;&nbsp;/* ITK objects needed for processing the volume&nbsp;&nbsp;*/
<br>&nbsp;&nbsp;ReaderType::Pointer reader = ReaderType::New();<br>&nbsp;&nbsp;ImageType::Pointer inputImage ;<br><br>&nbsp;&nbsp;ChopperType::Pointer chopper = ChopperType::New();<br>&nbsp;&nbsp;SampleType::Pointer sample = SampleType::New();<br>&nbsp;&nbsp;MeanAlgorithmType::Pointer meanAlgorithm = MeanAlgorithmType::New();
<br><br>&nbsp;&nbsp;&nbsp;&nbsp; ImageType::RegionType inputRegion;<br>&nbsp;&nbsp;&nbsp;&nbsp; ImageType::SizeType inputRegionSize;<br>&nbsp;&nbsp;&nbsp;&nbsp; ImageType::IndexType inputRegionIndex;<br><br>&nbsp;&nbsp;if (argc != 2){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Little program to use itk to calculate means of image
<br>area\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Usage: %s input.xxx \n&quot;,argv[0]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;where xxx is an ITK registered file type extension\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return(0);<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;/* Read in the&nbsp;&nbsp;image */
<br>&nbsp;&nbsp;printf(&quot;...reading\n&quot;);<br>&nbsp;&nbsp;reader-&gt;SetFileName(argv[1]);<br>&nbsp;&nbsp;inputImage=reader-&gt;GetOutput();<br>&nbsp;&nbsp;try {<br>&nbsp;&nbsp;&nbsp;&nbsp; inputImage-&gt;Update();<br>&nbsp;&nbsp;}catch( itk::ExceptionObject &amp; exp ) {<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;Exception caught inputImage update !&quot; &lt;&lt; std::endl;
<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; exp &lt;&lt; std::endl;<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;inputImage-&gt;DisconnectPipeline();<br><br>&nbsp;&nbsp;/* select the specified region to get the statistics */<br>&nbsp;&nbsp;inputRegion = inputImage-&gt;GetLargestPossibleRegion ();
<br>&nbsp;&nbsp;inputRegionSize = inputRegion.GetSize ();<br>&nbsp;&nbsp;inputRegionIndex = inputRegion.GetIndex ();<br><br>&nbsp;&nbsp;/* debugging output */<br>&nbsp;&nbsp;std::cout &lt;&lt; &quot;Region One: &quot; &lt;&lt; inputRegion &lt;&lt; std::endl;<br>
<br>&nbsp;&nbsp;/* loop through regions across the sample */<br>&nbsp;&nbsp;chopper-&gt;SetInput(inputImage);<br>&nbsp;&nbsp;for(i=0;i&lt;20;i+=5){<br>&nbsp;&nbsp;std::cout &lt;&lt; &quot;**********************************&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;std::cout &lt;&lt; &quot;* Region&nbsp;&nbsp;&nbsp;&nbsp;&quot; &lt;&lt; i &lt;&lt; &quot;*********************&quot; &lt;&lt;
<br>std::endl;<br>&nbsp;&nbsp;std::cout &lt;&lt; &quot;**********************************&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegionIndex[0]=i;<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegionIndex[1]=200;<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegionSize[0]=20;<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegionSize[1]=20;
<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegion.SetSize (inputRegionSize);<br>&nbsp;&nbsp;&nbsp;&nbsp; inputRegion.SetIndex (inputRegionIndex);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; chopper-&gt;SetExtractionRegion (inputRegion);<br><br>&nbsp;&nbsp;/* debugging output */<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Region Two: &quot; &lt;&lt;
<br>inputImage-&gt;GetLargestPossibleRegion() &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Region Three: &quot; &lt;&lt; inputRegion &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; //std::cout &lt;&lt; chopper &lt;&lt; std::endl;<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chopper-&gt;Update();<br>&nbsp;&nbsp;&nbsp;&nbsp; }catch( itk::ExceptionObject &amp; exp ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; &quot;Exception caught chopper update !&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; exp &lt;&lt; std::endl;
<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;/* debugging output */<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Region Four: &quot; &lt;&lt;<br>chopper-&gt;GetInput()-&gt;GetLargestPossibleRegion() &lt;&lt; std::endl;<br><br>&nbsp;&nbsp;&nbsp;&nbsp; /* pipe the image to the statistics package */
<br>&nbsp;&nbsp;&nbsp;&nbsp; sample-&gt;SetImage(chopper-&gt;GetOutput());<br>&nbsp;&nbsp;&nbsp;&nbsp; //sample-&gt;SetImage(inputImage);<br>&nbsp;&nbsp;&nbsp;&nbsp; meanAlgorithm-&gt;SetInputSample( sample);<br><br>&nbsp;&nbsp;&nbsp;&nbsp; /* get the mean greylevel */<br>&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;meanAlgorithm-&gt;Update();
<br>&nbsp;&nbsp;&nbsp;&nbsp; }catch( itk::ExceptionObject &amp; exp ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; &quot;Exception caught subImage update !&quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cerr &lt;&lt; exp &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Sample mean = &quot; &lt;&lt; *(meanAlgorithm-&gt;GetOutput()) &lt;&lt;
<br>std::endl;<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;printf(&quot;All done\n&quot;);<br>&nbsp;&nbsp;return (0);<br>}<br><br>_______________________________________________<br>Insight-users mailing list<br><a href="mailto:Insight-users@itk.org">Insight-users@itk.org
</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a><br></blockquote></div><br>