[Insight-users] multiple questions

Renaud Isabelle renauisa at yahoo.fr
Thu Nov 3 11:50:39 EST 2005


Hi, 
 
1- Does it already exist filters to compute variance and mean of images? Or do I have to write mine, maybe derived from UnaryFunctorImageFilter? 
 
2- Is it possible to write a composite filter built with multiple filters such as FFT filter?I tried to, but it seems that declaration of this kind of filter in my header file causes an error because of the type of the component filters. 
 
protected:
   typedef  VnlFFTRealToComplexConjugateImageFilter<float,2> FFTFilterType;
   typedef FFTFilterType::OutputImageType ComplexImageType;
   typedef itk::MultiplyComplexImageFilter<ComplexImageType, ComplexImageType,    ComplexImageType> MultiplyComplexImageFilter;
  typedef VnlFFTComplexConjugateToRealImageFilter< float,2 > IFFTFilterType;
 
private:
  typename FFTFilterType::Pointer m_FFTFilter1;
  typename FFTFilterType::Pointer m_FFTFilter2;
  typename MultiplyComplexImageFilter::Pointer m_MultiplyFilter;
  typename IFFTFilterType::Pointer m_IFFTFilter;
 
See, actually, I have to make a lot of filters call to compute the correlation matrix between my 2 inputs image. 
 
Here is all my procedure and actually it works fine. Now, I would like to incorporate all of this in one composite filter to make my implementation more automatic and easy to read. Do you t hink that it is possible? 
 
 //mean computation
  ImageRegionConstIterator inputit1(image1, image1->GetRequestedRegion());
  ImageRegionConstIterator inputit2(image2, image2->GetRequestedRegion());
  inputit1.GoToBegin();
  inputit2.GoToBegin();
  unsigned int NumberOfPixels = 0;
  float mean1 = 0.0;
  float mean2 = 0.0;
  while( !inputit1.IsAtEnd() ) 
  {
    mean1 += ((float)inputit1.Get());
   mean2 += ((float)inputit2.Get());
   NumberOfPixels++;
    ++inputit1;
   ++inputit2;
  }
  mean1 /= (float)NumberOfPixels;
  mean2 /= (float)NumberOfPixels;
 
  //centered matrices
  it1.GoToBegin(); 
  it2.GoToBegin();
  while( !it1.IsAtEnd() )
    {
    it1.Set(it1.Get()-mean1);
   it2.Set(it2.Get()-mean2);
   ++it1;
   ++it2;
    }
 
  //variances computation
   inputit1.GoToBegin();
   inputit2.GoToBegin();
  
   float var1 = 0.0;
   float var2 = 0.0;
   float tmp1, tmp2;
 
   while( !inputit1.IsAtEnd() ) 
   {
     tmp1 = (float)inputit1.Get();
    tmp2 = (float)inputit2.Get();
    var1 += SQUARE(tmp1);
    var2 += SQUARE(tmp2);
    ++inputit1;
    ++inputit2;
   }
 
  float denom = sqrt( var1 * var2 );
  if( denom!= 0.0) 
  {  
  
  typedef itk::VnlFFTRealToComplexConjugateImageFilter<float,2> FFTFilterType;
  FFTFilterType::Pointer fftFilter1 = FFTFilterType::New();
  fftFilter1->SetInput( image1);
  FFTFilterType::Pointer fftFilter2 = FFTFilterType::New();
  fftFilter2->SetInput( image2);
 
   //output type from the FFT filters
  typedef FFTFilterType::OutputImageType ComplexImageType;
  typedef itk::MultiplyComplexImageFilter<ComplexImageType, ComplexImageType, ComplexImageType> MultiplyComplexImageFilter;
  MultiplyComplexImageFilter::Pointer multiplyFilter = MultiplyComplexImageFilter::New();
  multiplyFilter->SetInput1( fftFilter1->GetOutput() );
  multiplyFilter->SetInput2( fftFilter2->GetOutput() );
  
  typedef itk::VnlFFTComplexConjugateToRealImageFilter< float,2 > IFFTFilterType;
  IFFTFilterType::Pointer ifftFilter = IFFTFilterType::New();
  ifftFilter->SetInput(multiplyFilter->GetOutput()); // try to recover the input image
  ifftFilter->Update();
   
  ImageRegionIterator out(ifftFilter->GetOutput(), ifftFilter->GetOutput()->GetRequestedRegion());
  out.GoToBegin();
  while( !out.IsAtEnd() )
    {
   out.Set(out.Get()/denom); 
    ++out;
    }
  }
 
Thank you for answering,
 
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/20051103/b10846af/attachment.html


More information about the Insight-users mailing list