[Insight-users] Bug in CastImageFilter?

Miller, James V (Research) millerjv@crd.ge.com
Mon, 10 Feb 2003 10:05:40 -0500


This is a standard problem in the pipeline mechanism.  

The issue is when Update() is called the first time, no
RequestedRegion is set in the pipeline so it defaults to 
setting the RequestedRegion to the LargestPossibleRegion.

When you swap the input to the CastImageFilter and call
Update() a second time, the pipeline (incorrectly) assumes
that you want to update the same RequestedRegion that you 
asked for (implicitly) the first time.  But you did not want
to update the same RequestedRegion, but rather, you wanted to
update a "new" RequestedRegion that matches the size of the image
coming from the pyramid.

The quick fix is to change the call to Update() in your loop
to UpdateLargestPossibleRegion().

Basically, there is currently no way for the pipeline to know
that the upstream data is not the same size as it used to be.

I hope to add some type of "flush" mechanism which will return 
a pipeline to its initial state so a user can change a input
upstream, flush the pipeline, and have an Update() do what a 
user would expect.

Jim



> -----Original Message-----
> From: Mark Hastenteufel [mailto:M.Hastenteufel@DKFZ-Heidelberg.de]
> Sent: Sunday, February 09, 2003 1:11 PM
> To: insight-users@public.kitware.com
> Subject: [Insight-users] Bug in CastImageFilter?
> 
> 
> Hi!
> 
> I've found a strange behaviour in itk::CastImageFilter. I've
> implemented a simple program which produces an image
> pyramid.
> The images on the respective level are written out to disk. The
> images are converted from float (internal type of PyramidFilter)
> to short using an ikt::CastImageFilter.
> 
> 
> Typedef's:
>   
>         typedef itk::Image<short,2> TInputImage2;
>         typedef itk::Image<double,2> TOutputImage;
>         typedef itk::MultiResolutionPyramidImageFilter< TOutputImage,
> TOutputImage > PyramidType;
>         typedef itk::CastImageFilter< TOutputImage,TInputImage2 >
> CastFilterType;
> 
> 
> If using the following code:
> 
> 
>   myPyramid->SetNumberOfLevels(noLevels);
>   myPyramid->SetInput( image );
>   myPyramid->UpdateLargestPossibleRegion();
> 
>   CastFilterType::Pointer myCaster = CastFilterType::New();
>   for (int i=0 ; i<noLevels ; i++)
>   {
>     myCaster->SetInput( myPyramid->GetOutput(i) );
>     myCaster->Update();
>                         
>     char s[100];
>     sprintf(s,"level%d.pic",i);
>     Pic2itk::saveImage<TInputImage2>(s,myCaster->GetOutput());
>   }
> 
> 
> just the image on the coarsest level is OK! The others are corrupted.
> This seems due to CastImageFilter. If declaring a cast-filter
> inside the for-loop, everything is OK!
> 
>   myPyramid->SetNumberOfLevels(noLevels);
>   myPyramid->SetInput(myCaster2->GetOutput() );
>   myPyramid->UpdateLargestPossibleRegion();
> 
>   for (int i=0 ; i<noLevels ; i++)
>   {
>     CastFilterType::Pointer myCaster = CastFilterType::New();
>     myCaster->SetInput( myPyramid->GetOutput(i) );
>     myCaster->Update();
>                         
>     char s[100];
>     sprintf(s,"level%d.pic",i);
>     Pic2itk::saveImage<TInputImage2>(s,myCaster->GetOutput());
>   }
> 
> 
> It seems, that the CastImageFilter doesn't work if SetInput is 
> called more than one time. Is this a bug or did I made something
> wrong?
> 
> 
> Mark
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>