<br><br>Hi Jameson,<br><br><br>If you want to reuse a reader in order to read <br>many images, you MUST:<br><br>A) Disconnect the output image at every use<br> of the reader,<br><br> and<br><br><br>B) Call reader->UpdateLargestPossibleRegion()<br>
instead of just calling reader->Update();<br><br><br>-------<br><br>Action (B) is fundamental if your input images<br>have different sizes.<br><br>------<br><br>Your code should be like:<br><br><br> std::vector< ImageType::Pointer > imageArray;<br>
<br> for( unsigned int i = 0; i < nimages; i++ )<br> {<br> reader->SetFileName( filenames[i] );<br> try<br> {<br> reader->UpdateLargestPossibleRegion();<br> }<br> catch( itk::ExceptionObject & excp )<br>
{<br> std::cerr << excp << std::endl;<br> return EXIT_FAILURE;<br> }<br> ImageType::Pointer image = reader->GetOutput();<br> image->DisconnectPipeline(); // IMPORTANT !!<br>
imageArray.push_back( image );<br><br> IteratorType itr( image, image->GetBufferedRegion() );<br> itr.GoToBegin();<br> itr.SetDirection( 0 );<br> while( ! itr.IsAtEnd() )<br> {<br>
// do something with the pixel<br> ++itr;<br> }<br><br> //... more stuff here<br> }<br><br><br>Note that even if you were not reusing the reader,<br>you MUST disconnect and image from its source<br>
before you use an iterator in order to modify its pixel<br>values. Otherwise you will lose your modification at<br>the next update of the pipeline.<br><br><br> Regards,<br><br><br> Luis<br><br><br>--------------------------------------------------------------<br>
<div class="gmail_quote">On Sat, Apr 24, 2010 at 5:06 PM, jmerkow <span dir="ltr"><<a href="mailto:jmerkow@andrew.cmu.edu">jmerkow@andrew.cmu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
I am trying to reintialize an input image that I pass to an iterator. I am<br>
doing this as follows:<br>
<br>
<br>
reader->SetFileName( argv[i] );<br>
try<br>
{<br>
reader->Update();<br>
}<br>
catch ( itk::ExceptionObject &err)<br>
{<br>
std::cout << "ExceptionObject caught a !" << std::endl;<br>
std::cout << err << std::endl;<br>
return -1;<br>
}<br>
<br>
IteratorType<br>
iter(reader->GetOutput(),reader->GetOutput()->GetRequestedRegion());<br>
iter.SetDirection(0);<br>
<br>
<br>
This code is part of a loop, each iteration in the loop I want to read a new<br>
image, and use it to create the iterator.<br>
<br>
I get this error when I try to do this:<br>
<br>
ExceptionObject caught a !<br>
<br>
itk::InvalidRequestedRegionError (00C3FE28)<br>
Location: "void __thiscall itk::DataObject::PropagateRequestedRegion(void)<br>
throw<br>
(class itk::InvalidRequestedRegionError)"<br>
File: ..\..\..\..\Source\InsightToolkit-3.16.0\Code\Common\itkDataObject.cxx<br>
Line: 397<br>
Description: Requested region is (at least partially) outside the largest<br>
possible region.<br>
<br>
<br>
Thanks for the help!<br>
<br>
Jameson<br>
--<br>
View this message in context: <a href="http://itk-insight-users.2283740.n2.nabble.com/ImageType-Pointer-Help-Reintialize-with-a-new-image-tp4956407p4956407.html" target="_blank">http://itk-insight-users.2283740.n2.nabble.com/ImageType-Pointer-Help-Reintialize-with-a-new-image-tp4956407p4956407.html</a><br>
Sent from the ITK Insight Users mailing list archive at Nabble.com.<br>
_____________________________________<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/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/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_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/listinfo/insight-users</a><br>
</blockquote></div><br>