[Insight-users] Using an ITK reader multiple times

Luis Ibanez luis.ibanez at kitware.com
Fri Oct 9 11:41:09 EDT 2009


Hi Dirk,

Yes, indeed.

When reusing a reader you must call:

        reader->UpdateLargestPossibleRegion()

instead of the usual:

                    reader->Update()

Otherwise the extent of the previous image
is kept, and in some cases lead to Exceptions
being thrown if the second image is smaller
than the first one.


It is arguable whether this is a "bug" or a "feature".


I would vote for changing the behavior of Update()
in the readers, since we have found this issue
very often.

There may be some backward-compatibility
implications, in which case we may have to
keep this in mind for ITK 4.0.


      Regards,


             Luis


---------------------------------------------------------------------
On Fri, Oct 9, 2009 at 6:04 AM, Dirk Boye <body at nabla.org> wrote:
> Dear listmembers,
> I am trying to use the ITK reader multiple times and the dimensions wont
> get updated.
>
> typedef itk::ImageFileReader<ImageType>                 ReaderType;
> typedef itk::ImageToVTKImageFilter<ImageType>           ConnectorType;
>
> ...
> // member pointers of a class a
> mp_readeritk = ReaderType::New();
> mp_connector = ConnectorType::New();
>
> a::loadImage(fileName) {
> mp_readeritk->ResetPipeline();
> mp_readeritk->SetFileName( fileName.toStdString().c_str() );
>
> mp_readeritk->UpdateLargestPossibleRegion();
> mp_readeritk->Update();
> mp_readeritk->GetOutput()->Update();
> mp_readeritk->GetOutput()->UpdateOutputInformation();
>
> mp_connector->ResetPipeline();
> mp_connector->SetInput( mp_readeritk->GetOutput() );
>
> mp_connector->UpdateLargestPossibleRegion();
> mp_connector->Update();
> mp_connector->UpdateOutputInformation();
> mp_connector->GetOutput()->UpdateData();
> mp_connector->GetOutput()->UpdateInformation();
> mp_connector->GetOutput()->Update();
>
> mp_connector->GetOutput()->GetDimensions(m_dimensions);
> // m_dimensions is of type int[3]
> }
>
> As you can see I tried alot of Updates :-)
> When i load the first image, m_dimensions is correct. When i load
> the second image later on, m_dimensions still has the values from the
> first time. If i load the second image again (calling load a third time)
> the values are correct. If i load (1st image, 2nd image, 1st image) the
> values are always the ones of the 1st image.
>
> To sum up:
> (1st image) -> m_dimensions = 1st image dim
> (1st image, 2nd image) -> m_dimensions= 1st image dim
> (1st , 2nd, 1st) -> m_dimensions=1st image dim
> (1st , 2nd, 2nd) -> m_dimensions=2nd image dim
>
> Has it something to do with the update extent?
>
> I don't understand it.
>
>
> Thank you!
>
> Cheers,
> Dirk
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.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
>


More information about the Insight-users mailing list