[Insight-users] Bug in CastImageFilter?

Mark Hastenteufel M.Hastenteufel@DKFZ-Heidelberg.de
Sun, 09 Feb 2003 19:10:55 +0100


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