[Insight-users] Bug in CastImageFilter?

Luis Ibanez luis.ibanez@kitware.com
Sun, 09 Feb 2003 21:18:43 -0500


Hi Mark,

Thanks for reporting this.

This is quite interesting since the CastImageFilter
is pretty simple. Most of its functionality is
actually implemented in its base class the
itkUnaryFunctorImageFilter which derives from
ImageToImageFilter, like:



     ImageToImageFilter
             ^
             |
             |
    UnaryFunctorImageFilter
             ^
             |
             |
      CastImageFilter


The UnaryFunctorImagefilter implements all the
pixel-wise operation on the toolkit.

The miss behaviour that you reported looks like
a problem in the negotiation of regions that
preceed the execution of the filter.  It makes
suspect that the regions are negociated in the
first call, and not in the subsequent calls.
If this bug is there, it is affecting all the
other pixel-wise filter on the toolkit.


However, there is also the possibility that
the problem is caused by the writer filter that
receives the output of the caster.


Have you find during your trials any hint
indicating that the actual problem is produced
by the Caster and not the following writers ?

For example, you could remove the caster from
the pipeline and use a float image type to
write in MetaImage format (which support
float pixel types).  Then use the MetaImageViewer
application to verify the content of your output
images.


This should help to eliminate one of the two
suspects here.


Please let us know what you find,


   Thanks


      Luis



----------------------------


Mark Hastenteufel wrote:

> 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
> 
>