<DIV>Hi guys, </DIV>
<DIV> </DIV>
<DIV>I am trying to write my own filter taking 2 inputs of the same type. For the moment, to test my filter, I am just trying to compute the mean and variance of each input in the GenerateData() method. However, at execution, my filter doesn't return!!!!</DIV>
<DIV> </DIV>
<DIV>Could you tell me what I am missing? </DIV>
<DIV> </DIV>
<DIV>Isabelle</DIV>
<DIV> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>/*=========================================================================</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> Module: itkCorrelationCoefficientsImageFilter.txx<BR> Language: C++<BR> Date: </STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG>=========================================================================*/<BR>#ifndef __itkCorrelationCoefficientsImageFilter_txx<BR>#define __itkCorrelationCoefficientsImageFilter_txx</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>#include "itkCorrelationCoefficientsImageFilter.h"<BR>#include "itkProgressReporter.h"<BR>#include "itkImageRegionIterator.h"<BR>#include "itkImageRegionConstIterator.h"</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG>#include "stdafx.h" //AfxMessageBox, CString</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>namespace itk {</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::CorrelationCoefficientsImageFilter()<BR>{<BR> this->SetNumberOfRequiredInputs(2);<BR>}</STRONG></FONT></DIV>
<DIV><BR><FONT face="comic sans ms"><STRONG>/* Connect the 1st input */<BR>template <class TInputImage, class TOutputImage><BR>void<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::SetInput1( const TInputImage * image1 ) <BR>{<BR> // Process object is not const-correct so the const casting is required.<BR> SetNthInput(0, const_cast<TInputImage *>( image1 ));<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>const TInputImage *<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::GetInput1()<BR>{<BR> return this->GetInput(0);<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG>/* Connect the 2nd input */<BR>template <class TInputImage, class TOutputImage><BR>void<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::SetInput2( const TInputImage * image2 ) <BR>{<BR> // Process object is not const-correct so the const casting is required.<BR> SetNthInput(1, const_cast<TInputImage *>( image2 ));<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>const TInputImage *<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::GetInput2()<BR>{<BR> return this->GetInput(1);<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>void <BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::GenerateInputRequestedRegion()<BR>{<BR> // call the superclass' implementation of this method<BR> Superclass::GenerateInputRequestedRegion();//ImageToImageFilter</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> // get pointers to the inputs<BR> Input1ImagePointer inputPtr1<BR> = const_cast< TInputImage*>( this->GetInput(0) );</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> Input2ImagePointer inputPtr2<BR> = const_cast< TInputImage*>( this->GetInput(1) );</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> if ( !inputPtr1 || !inputPtr2 ) return;</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> // We need to configure the inputs such that all the data is available.<BR> inputPtr1->SetRequestedRegion(inputPtr1->GetLargestPossibleRegion());<BR> inputPtr2->SetRequestedRegion(inputPtr2->GetLargestPossibleRegion());<BR>}</STRONG></FONT></DIV>
<DIV><BR><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>void <BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::EnlargeOutputRequestedRegion(DataObject *)<BR>{<BR> this->GetOutput()<BR> ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() );<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>float<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::Mean(TInputImage* input) const<BR>{<BR> ImageRegionConstIteratorType it(input, input->GetRequestedRegion());<BR> it.GoToBegin();</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> unsigned int NumberOfPixels = 0;<BR> float mean = 0.0;<BR> while( !it.IsAtEnd() ) <BR> {<BR> mean += ((float)it.Get());<BR> NumberOfPixels++;<BR> ++it;<BR> }</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> mean /= (float)NumberOfPixels;</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> return mean;<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>float<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::Variance(TInputImage* input, float mean) const<BR>{<BR> ImageRegionConstIteratorType it(input, input->GetRequestedRegion());<BR> <BR> it.GoToBegin();<BR> float sum = 0.0;<BR> float tmp; <BR> while( !it.IsAtEnd() ) <BR> {<BR> tmp = ((float)it.Get()) - mean;<BR> sum += (tmp)*(tmp);<BR> }</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> return sum;<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG>template <class TInputImage, class TOutputImage><BR>void<BR>CorrelationCoefficientsImageFilter<TInputImage, TOutputImage><BR>::GenerateData()<BR>{<BR> this->AllocateOutputs();</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> // get pointers to the inputs<BR> Input1ImagePointer inputPtr1<BR> = const_cast< TInputImage*>( this->GetInput(0) );</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> Input2ImagePointer inputPtr2<BR> = const_cast< TInputImage*>( this->GetInput(1) );</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> OutputImagePointer outputPtr = this->GetOutput(0); <BR> <BR> // the inputs must have the same size<BR> if ( this->GetInput1()->GetRequestedRegion().GetSize() != this->GetInput2()->GetRequestedRegion().GetSize() )<BR> {<BR> AfxMessageBox("The two input images must have the same size.");<BR> }</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> float meanX = this->Mean(inputPtr1);<BR> float meanY = this->Mean(inputPtr2);<BR> TRACE("means:%f, %f\n", meanX,meanY); //this is ok</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG> float varX = this->Variance(inputPtr1, meanX);<BR> float varY = this->Variance(inputPtr2, meanY);</STRONG></FONT></DIV>
<DIV><FONT face="Comic Sans MS"><STRONG></STRONG></FONT> </DIV>
<DIV><FONT face="comic sans ms"><STRONG> // iterator for the first input<BR> ImageRegionConstIteratorType inputIt1(this->GetInput1(), this->GetInput1()->GetRequestedRegion());<BR> <BR> // iterator for the 2nd input<BR> ImageRegionConstIteratorType inputIt2(this->GetInput2(), this->GetInput2()->GetRequestedRegion());<BR> <BR> // iterator for output image<BR> typedef ImageRegionIterator< TOutputImage > ImageRegionIteratorType;<BR> ImageRegionIteratorType outputIt( this->GetOutput(), this->GetOutput()->GetRequestedRegion() );<BR> <BR> inputIt1.GoToBegin();<BR> inputIt2.GoToBegin();<BR> outputIt.GoToBegin();</STRONG></FONT></DIV>
<DIV><BR><FONT face="comic sans ms"><STRONG> InputImagePixelType denom = sqrt( varX * varY );</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> if( denom == 0.0) <BR> AfxMessageBox("Coefficient de Correlation non defini, variance nulle!\n");</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> //else<BR> //{<BR> // Set up the progress reporter <BR> ProgressReporter progress(this, 0, this->GetInput1()->GetRequestedRegion().GetNumberOfPixels());</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> while( !inputIt1.IsAtEnd() ) <BR> {<BR> ++inputIt1;<BR> progress.CompletedPixel(); // potential exception thrown here<BR> } <BR> //}<BR>}</STRONG></FONT></DIV>
<DIV><FONT face="comic sans ms"><STRONG> <BR>}// end namespace itk<BR>#endif</STRONG></FONT></DIV><p>
                <hr size=1>
<b><font color=#FF0000>Appel audio GRATUIT</font> partout dans le monde</b> avec le nouveau Yahoo! Messenger<br>
<a href="http://us.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com">Téléchargez le ici !</a>