[Insight-users] ImageType Pointer Help. Reintialize with a new image

Luis Ibanez luis.ibanez at kitware.com
Sun Apr 25 10:58:21 EDT 2010


Hi  Jameson,


If you want to reuse a reader in order to read
many images, you MUST:

A) Disconnect the output image at every use
     of the reader,

    and


B)  Call reader->UpdateLargestPossibleRegion()
      instead of just calling reader->Update();


-------

Action (B) is fundamental if your input images
have different sizes.

------

Your code should be like:


    std::vector< ImageType::Pointer > imageArray;

    for( unsigned int i = 0; i < nimages; i++ )
       {
       reader->SetFileName( filenames[i] );
       try
          {
          reader->UpdateLargestPossibleRegion();
          }
       catch( itk::ExceptionObject & excp )
         {
         std::cerr << excp << std::endl;
         return EXIT_FAILURE;
         }
       ImageType::Pointer image = reader->GetOutput();
       image->DisconnectPipeline(); // IMPORTANT !!
       imageArray.push_back( image );

       IteratorType itr( image, image->GetBufferedRegion() );
       itr.GoToBegin();
       itr.SetDirection( 0 );
       while( ! itr.IsAtEnd() )
           {
           // do something with the pixel
           ++itr;
           }

       //... more stuff here
       }


Note that even if you were not reusing the reader,
you MUST disconnect and image from its source
before you use an iterator in order to modify its pixel
values. Otherwise you will lose your modification at
the next update of the pipeline.


     Regards,


          Luis


--------------------------------------------------------------
On Sat, Apr 24, 2010 at 5:06 PM, jmerkow <jmerkow at andrew.cmu.edu> wrote:

>
> I am trying to reintialize an input image that I pass to an iterator.  I am
> doing this as follows:
>
>
>                reader->SetFileName( argv[i] );
>                try
>                {
>                        reader->Update();
>                }
>                catch ( itk::ExceptionObject &err)
>                {
>                        std::cout << "ExceptionObject caught a !" <<
> std::endl;
>                        std::cout << err << std::endl;
>                        return -1;
>                }
>
>                IteratorType
> iter(reader->GetOutput(),reader->GetOutput()->GetRequestedRegion());
>                iter.SetDirection(0);
>
>
> This code is part of a loop, each iteration in the loop I want to read a
> new
> image, and use it to create the iterator.
>
> I get this error when I try to do this:
>
> ExceptionObject caught a !
>
> itk::InvalidRequestedRegionError (00C3FE28)
> Location: "void __thiscall itk::DataObject::PropagateRequestedRegion(void)
> throw
> (class itk::InvalidRequestedRegionError)"
> File:
> ..\..\..\..\Source\InsightToolkit-3.16.0\Code\Common\itkDataObject.cxx
> Line: 397
> Description: Requested region is (at least partially) outside the largest
> possible region.
>
>
> Thanks for the help!
>
> Jameson
> --
> View this message in context:
> http://itk-insight-users.2283740.n2.nabble.com/ImageType-Pointer-Help-Reintialize-with-a-new-image-tp4956407p4956407.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100425/fbd50a3e/attachment-0001.htm>


More information about the Insight-users mailing list