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. This is what the exception is reporting. 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> <<a href="mailto:r.atwood@imperial.ac.uk">r.atwood@imperial.ac.uk
</a>> 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> Dimension: 2<br> Index: [0, 0]<br> Size: [1015, 512]<br><br>Region Two: ImageRegion (0x602118)<br>
Dimension: 2<br> Index: [0, 0]<br> Size: [1015, 512]<br><br>Region Three: ImageRegion (0x7fbfffde70)<br> Dimension: 2<br> Index: [0, 200]<br> Size: [20, 20]<br><br>Region Four: ImageRegion (0x602118)<br> Dimension: 2
<br> Index: [0, 0]<br> Size: [1015, 512]<br><br>Sample mean = [18226.6]<br>Region Two: ImageRegion (0x602118)<br> Dimension: 2<br> Index: [0, 0]<br> Size: [1015, 512]<br><br>Region Three: ImageRegion (0x7fbfffde70)<br>
Dimension: 2<br> Index: [5, 200]<br> Size: [20, 20]<br><br>Exception caught chopper update !<br><br>itk::InvalidRequestedRegionError (0x614500)<br>Location: "virtual void itk::DataObject::PropagateRequestedRegion()"
<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>
Dimension: 2<br> Index: [0, 0]<br> Size: [1015, 512]<br><br>Sample mean = [18226.6]<br><br><br><br><br>****************** The Code *************************************<br><br>#include <stdio.h><br><br>#include "
itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkScalarImageToListAdaptor.h"<br>#include "itkScalarToArrayCastImageFilter.h"<br>#include "itkMeanCalculator.h"<br>
#include "itkExtractImageFilter.h"<br>#include "itkRegionOfInterestImageFilter.h"<br><br>#ifdef T_FLOAT<br> typedef float PixelType;<br>#elif defined T_BYTE<br> typedef unsigned char PixelType;<br>#elif defined T_USHORT
<br> typedef unsigned short PixelType;<br>#elif defined T_UINT<br> typedef u_int32_t PixelType;<br>#else<br>#warning NO TYPE DEFINED, defaulting to FLOAT<br> typedef float PixelType;<br>#endif<br><br><br> typedef itk::Image< PixelType, 2 > ImageType;
<br><br> // definitions for writing the image<br> typedef itk::ImageFileReader<ImageType> ReaderType;<br> typedef itk::FixedArray< PixelType, 1 > MeasurementVectorType;<br> typedef itk::Image< MeasurementVectorType, 2 > ArrayImageType;
<br> typedef itk::Statistics::ScalarImageToListAdaptor< ImageType ><br>SampleType;<br> typedef itk::Statistics::MeanCalculator< SampleType ><br>MeanAlgorithmType;<br> typedef itk::ExtractImageFilter<ImageType,ImageType> ChopperType;
<br>/*********************************/<br>/* beginning of MAIN routine */<br>/*********************************/<br>int main(int argc, char ** argv) {<br> int i,j;<br><br> /* ITK objects needed for processing the volume */
<br> ReaderType::Pointer reader = ReaderType::New();<br> ImageType::Pointer inputImage ;<br><br> ChopperType::Pointer chopper = ChopperType::New();<br> SampleType::Pointer sample = SampleType::New();<br> MeanAlgorithmType::Pointer meanAlgorithm = MeanAlgorithmType::New();
<br><br> ImageType::RegionType inputRegion;<br> ImageType::SizeType inputRegionSize;<br> ImageType::IndexType inputRegionIndex;<br><br> if (argc != 2){<br> printf("Little program to use itk to calculate means of image
<br>area\n");<br> printf("Usage: %s input.xxx \n",argv[0]);<br> printf("where xxx is an ITK registered file type extension\n");<br> return(0);<br> }<br><br> /* Read in the image */
<br> printf("...reading\n");<br> reader->SetFileName(argv[1]);<br> inputImage=reader->GetOutput();<br> try {<br> inputImage->Update();<br> }catch( itk::ExceptionObject & exp ) {<br> std::cerr << "Exception caught inputImage update !" << std::endl;
<br> std::cerr << exp << std::endl;<br> }<br> inputImage->DisconnectPipeline();<br><br> /* select the specified region to get the statistics */<br> inputRegion = inputImage->GetLargestPossibleRegion ();
<br> inputRegionSize = inputRegion.GetSize ();<br> inputRegionIndex = inputRegion.GetIndex ();<br><br> /* debugging output */<br> std::cout << "Region One: " << inputRegion << std::endl;<br>
<br> /* loop through regions across the sample */<br> chopper->SetInput(inputImage);<br> for(i=0;i<20;i+=5){<br> std::cout << "**********************************" << std::endl;<br> std::cout << "* Region " << i << "*********************" <<
<br>std::endl;<br> std::cout << "**********************************" << std::endl;<br> inputRegionIndex[0]=i;<br> inputRegionIndex[1]=200;<br> inputRegionSize[0]=20;<br> inputRegionSize[1]=20;
<br> inputRegion.SetSize (inputRegionSize);<br> inputRegion.SetIndex (inputRegionIndex);<br><br> chopper->SetExtractionRegion (inputRegion);<br><br> /* debugging output */<br> std::cout << "Region Two: " <<
<br>inputImage->GetLargestPossibleRegion() << std::endl;<br> std::cout << "Region Three: " << inputRegion << std::endl;<br> //std::cout << chopper << std::endl;<br>
<br> try {<br> chopper->Update();<br> }catch( itk::ExceptionObject & exp ) {<br> std::cerr << "Exception caught chopper update !" << std::endl;<br> std::cerr << exp << std::endl;
<br> }<br> /* debugging output */<br> std::cout << "Region Four: " <<<br>chopper->GetInput()->GetLargestPossibleRegion() << std::endl;<br><br> /* pipe the image to the statistics package */
<br> sample->SetImage(chopper->GetOutput());<br> //sample->SetImage(inputImage);<br> meanAlgorithm->SetInputSample( sample);<br><br> /* get the mean greylevel */<br> try {<br> meanAlgorithm->Update();
<br> }catch( itk::ExceptionObject & exp ) {<br> std::cerr << "Exception caught subImage update !" << std::endl;<br> std::cerr << exp << std::endl;<br> }<br> std::cout << "Sample mean = " << *(meanAlgorithm->GetOutput()) <<
<br>std::endl;<br> }<br> printf("All done\n");<br> 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>