Robert,<br><br>You can call UpdateLargestPossibleRegion() on an entire pipeline. <br>UpdateLargestPossibleRegion() forces the pipeline to act like as if it were<br>being executed for the first time.<br><br>You need to call UpdateLargestPossibleRegion() (or explictly set an
<br>RequestedRegion) whenever a change in filter parameters may result<br>in a cached region to fall outside the "new" LargestPossibleRegion.<br>There are only a few instances where this can happen. Filters like
<br>ExtractImageFilter, filters like ShrinkImageFilter, etc. <br><br>The RegionOfInterestImageFilter may not exhibit this issue because<br>of the differences between it and the ExtractImageFilter.<br><br>ExtractImageFilter maintains the "index" relationship between the input
<br>and output image. Thus, the StartIndex of the output image is exactly<br>the index specified as the extraction region. A side effect of this is that<br>the origin is unchanged.<br><br>RegionOfInterestImageFilter shifts the "index" relationship between the input
<br>and output image. Here, the StartIndex of the output image is always [0,0,...].<br>As a side effect, the origin of the output is also modified.<br><br>The output of the ExtractImageFilter is always pixel aligned with the input
<br>image. The output of the RegionOfInterestImageFilter is always aligned<br>in physical space (say mm) with the input image.<br><br>Jim<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;">
Jim:<br><br>I take it you mean when updating the ExtractImageFilter itself ? What<br>about when the filter is part of a pipeline, can you call<br>UpdateLargestPossibleRegion() on the end of the pipeline or do you need<br>
to explicity call it on the ExtractImageFilter? The example I sent was<br>minimal to illustrate my problem, in the end I want to apply some other<br>filters in a pipeline. The example on p277 of the software guide does<br>
not call this method, but the filter is part of a pipeline ... And it is<br>not in a loop, or used more than once!<br><br>Is this the case for RegionOfInterestImageFilter? I tried that since<br>posting and it does not seem to generate such an exception for my
<br>program. Is that just luck? Should I use UpdateLargestPossibleRegion()<br>in this case?<br><br><br>Thanks again!<br><br>Robert<br><br>-----Original Message-----<br>From: Jim Miller [mailto:<a href="mailto:millerjv@gmail.com">
millerjv@gmail.com</a>]<br>Sent: 05 June 2006 21:25<br>To: Atwood, Robert C<br>Cc: Insight Users<br>Subject: Re: [Insight-users] Extract image in a loop, I don't understand<br>why it does not work<br><br>Robert,<br><br>When you update the ExtractImageFilter, you should call
<br>UpdateLargestPossibleRegion() instead of<br>calling Update(). When a region is changed, there is a possibility that<br>the data cached in pipeline<br>may not be valid. This is what the exception is reporting. A call to
<br>UpdateLargestPossibleRegion()<br>tells the pipeline to ignore any cached region sizes.<br><br>Jim<br><br><br><br><br>On 6/5/06, Atwood, Robert C <<a href="mailto:r.atwood@imperial.ac.uk">r.atwood@imperial.ac.uk</a>
> wrote:<br><br> Hi,<br> I am trying to obtain the statistics for some specified regions<br>of an<br> image (eventualy each of several images)<br> I seem to be getting an exception thrown the second time I try
<br>to<br> extract a region. Is there something that needs to be done to<br>reset the<br> extractImagefilter?<br><br> In this case I defined the pixel type to unsigned short and the<br>input<br> image is 1015x512. With this example the size of the region is
<br>20x20 and<br> the index starts at 0,200 and increases by 5,0 until 20,200 so<br>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<br>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<br>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><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><br> typedef itk::Statistics::ScalarImageToListAdaptor< ImageType ><br> SampleType;<br> typedef itk::Statistics::MeanCalculator< SampleType ><br> MeanAlgorithmType;<br> typedef itk::ExtractImageFilter<ImageType,ImageType>
<br>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 =<br>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<br>image<br> area\n");<br> printf("Usage: %s
input.xxx \n",argv[0]);<br> printf("where xxx is an ITK registered file type<br>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 !" <<
<br>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 << "**********************************" <<
<br>std::endl;<br> std::cout << "* Region " << i << "*********************" <<<br><br> std::endl;<br> std::cout << "**********************************" <<
<br>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 !" <<<br>
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 !" <<
<br>std::endl;<br> std::cerr << exp << std::endl;<br> }<br> std::cout << "Sample mean = " <<<br>*(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><br><br><br></blockquote></div><br>