[Insight-users] help with how to write a correct filter

Renaud Isabelle renauisa at yahoo.fr
Mon Aug 8 13:45:18 EDT 2005


Hi,
 
I implemented a function to compute the envelop of my raw image imageInitiale. This works fine:
 
void ComputeSignalAnalytic()
{
  //Declarations
  WorkImageType::RegionType region = imageInitiale->GetBufferedRegion();  
  enveloppeImage->SetRegions(region);
  enveloppeImage->SetSpacing(imageInitiale->GetSpacing());
  enveloppeImage->SetOrigin( imageInitiale->GetOrigin());
  enveloppeImage->Allocate();
 
  typedef itk::ImageRegionConstIterator<ImageType3D> ConstIteratorType;
  ConstIteratorType inputIt(imageInitiale, region);
  IteratorType outputIt(enveloppeImage, region);
  inputIt.GoToBegin();
  outputIt.GoToBegin();
 
  int i;
  int nn =nextpow2(width);
  float* VectImgR = (float*)malloc(nn*sizeof(float));
  float* VectImgI = (float*)malloc(nn*sizeof(float));
 
  while(!inputIt.IsAtEnd())
  {

 for(i=0;i<nn;i++) VectImgI[i] = VectImgR[i] = 0.0;
    for(i=0;i<width;i++) 
    {
  VectImgR[i] = (float)inputIt.Get(); 
  ++inputIt;
    }
 
 hilbert(VectImgR,VectImgI,nn);//Hilbert
 
 for(i=0;i<width;i++)
 {
  outputIt.Set(sqrt( SQUARE(VectImgR[i])+SQUARE(VectImgI[i]) ));
  ++outputIt;
 }

  }   
  free(VectImgR);
  free(VectImgI);
} 
 
This is called like this:
 
ImageType3D::ConstPointer imageInitiale  = reader->GetOutput();
WorkImageType::Pointer enveloppeImage;

      
ComputeSignalAnalytic();
 
But for now, I'm triing to compute the envelop of my image in a filter instead. I'm doing exactly the same thing but in a filter: 
 
template<class TInputImage, class TOutputImage>
void
EnvelopImageFilter<TInputImage, TOutputImage>
::GenerateInputRequestedRegion()
{
  Superclass::GenerateInputRequestedRegion();
  if ( this->GetInput() )
    {
    InputImagePointer image =
      const_cast< typename Superclass::InputImageType * >( this->GetInput() );
    image->SetRequestedRegionToLargestPossibleRegion();
    }
}
 
template<class TInputImage, class TOutputImage>
void
EnvelopImageFilter<TInputImage, TOutputImage>
::EnlargeOutputRequestedRegion(DataObject *data)
{
  Superclass::EnlargeOutputRequestedRegion(data);
  data->SetRequestedRegionToLargestPossibleRegion();
}
 
template<class TInputImage, class TOutputImage>
void
EnvelopImageFilter<TInputImage, TOutputImage>
::GenerateData()
{
  typedef TInputImage  InputImageType;
  typedef TOutputImage OutputImageType;
  typename InputImageType::ConstPointer input = this->GetInput();
  typename OutputImageType::Pointer output = this->GetOutput();
  typedef typename InputImageType::PixelType InputPixelType;
  typedef typename OutputImageType::PixelType OutputPixelType;
  
  // Allocate the output
  this->AllocateOutputs();
  // Iterator which traverse the input
  ImageRegionConstIterator<InputImageType> itInput(input, 
                                              input->GetRequestedRegion());
 
  unsigned int i;
  int width = input->GetRequestedRegion().GetSize()[0]; 
  int nn =nextpow2(width);
  float* VectImgR = (float*)malloc(nn*sizeof(float));
  float* VectImgI = (float*)malloc(nn*sizeof(float)); 
 
    // iterator for the output
   ImageRegionIterator<OutputImageType> itOut(output, output->GetRequestedRegion());
 
   ProgressReporter progress(this,0,output->GetRequestedRegion().GetNumberOfPixels());
 
  itInput.GoToBegin();
  itOut.GoToBegin();
  while ( ! itInput.IsAtEnd() )
  {
    for(i=0;i<nn;i++) VectImgI[i] = VectImgR[i] = 0.0;
    for(i=0;i<width;i++) 
    {
     VectImgR[i] = static_cast<float>(itInput.Get());
  ++ itInput;
    }
 
    hilbert(VectImgR,VectImgI,nn);//Hilbert
 
    for(i=0;i<width;i++)
    {
      itOut.Set((OutputPixelType)( SQUARE(VectImgR[i])+SQUARE(VectImgI[i]) ));
      ++itOut;
    progress.CompletedPixel();
    }
  }  
  
  free(VectImgR);
  free(VectImgI);  
}
 
Exactly the same code is done in my function GenerateData(). However, 
 
envelopFilter->SetInput(imageInitiale);
envelopFilter->Update();
enveloppeImage = envelopFilter->GetOutput(); 
 
doesn't produce the same result.
 
Could anyone tell me why? 
 
Please help me to handle it,
 
isabelle

		
---------------------------------
 Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
 Téléchargez le ici !  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050808/d80bf935/attachment.htm


More information about the Insight-users mailing list