8 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
11 this->SetNthInput(0, const_cast<TInputImage*>(image));
14 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
17 this->SetNthInput(1, const_cast<TInputImage*>(image));
20 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
23 this->SetNthInput(2, const_cast<TInputImage*>(image));
26 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
29 this->SetNthInput(3, const_cast<TMaskImage*>(mask));
32 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
35 return static_cast< const TInputImage *
> 36 ( this->itk::ProcessObject::GetInput(0) );
39 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
42 return static_cast< const TInputImage *
> 43 ( this->itk::ProcessObject::GetInput(1) );
46 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
49 return static_cast< const TInputImage *
> 50 ( this->itk::ProcessObject::GetInput(2) );
53 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
56 return static_cast< const TMaskImage *
> 57 ( this->itk::ProcessObject::GetInput(3) );
61 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
64 itk::DataObject::Pointer output;
69 output = ( TOutput::New() ).GetPointer();
72 output = ( TOutput::New() ).GetPointer();
75 output = ( TOutput::New() ).GetPointer();
78 output = ( TOutput::New() ).GetPointer();
81 output = ( TOutput::New() ).GetPointer();
84 std::cerr <<
"No output " << idx << std::endl;
88 return output.GetPointer();
91 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
94 return dynamic_cast< OutputImageType *
>( this->itk::ProcessObject::GetOutput(0) );
96 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
99 return dynamic_cast< OutputImageType *
>( this->itk::ProcessObject::GetOutput(1) );
101 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
104 return dynamic_cast< OutputImageType *
>( this->itk::ProcessObject::GetOutput(2) );
106 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
109 return dynamic_cast< OutputImageType *
>( this->itk::ProcessObject::GetOutput(3) );
111 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
114 return dynamic_cast< OutputImageType *
>( this->itk::ProcessObject::GetOutput(4) );
117 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
121 if( m_OutputMahaCSFFilename !=
"" )
123 std::cout <<
"Writing mahalanobis CSF image to: " << m_OutputMahaCSFFilename << std::endl;
124 anima::writeImage<TOutput>(m_OutputMahaCSFFilename, this->GetOutputMahaCSF());
126 if( m_OutputMahaGMFilename !=
"" )
128 std::cout <<
"Writing mahalanobis GM image to: " << m_OutputMahaGMFilename << std::endl;
129 anima::writeImage<TOutput>(m_OutputMahaGMFilename, this->GetOutputMahaGM());
131 if( m_OutputMahaWMFilename !=
"" )
133 std::cout <<
"Writing mahalanobis WM image to: " << m_OutputMahaWMFilename << std::endl;
134 anima::writeImage<TOutput>(m_OutputMahaWMFilename, this->GetOutputMahaWM());
136 if( m_OutputMahaMinimumFilename !=
"" )
138 std::cout <<
"Writing minimum mahalanobis image to: " << m_OutputMahaMinimumFilename << std::endl;
139 anima::writeImage<TOutput>(m_OutputMahaMinimumFilename, this->GetOutputMahaMinimum());
141 if( m_OutputMahaMaximumFilename !=
"" )
143 std::cout <<
"Writing maximum mahalanobis image to: " << m_OutputMahaMaximumFilename << std::endl;
144 anima::writeImage<TOutput>(m_OutputMahaMaximumFilename, this->GetOutputMahaMaximum());
148 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
151 ::BeforeThreadedGenerateData()
153 if(m_GaussianModel.size() != 3)
155 std::cout <<
"Error in mahalanobis filter: number of images do not correspond to solution size exiting..."<< std::endl;
159 m_InputImage_1_UC = ImageTypeUC::New();
160 m_InputImage_2_UC = ImageTypeUC::New();
161 m_InputImage_3_UC = ImageTypeUC::New();
164 double desiredMinimum=0,desiredMaximum=255;
166 typename RescaleFilterType::Pointer rescaleFilter1 = RescaleFilterType::New();
167 rescaleFilter1->SetInput( this->GetInputImage1() );
168 rescaleFilter1->SetOutputMinimum( desiredMinimum );
169 rescaleFilter1->SetOutputMaximum( desiredMaximum );
170 rescaleFilter1->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
171 rescaleFilter1->SetCoordinateTolerance(m_Tol);
172 rescaleFilter1->SetDirectionTolerance(m_Tol);
173 rescaleFilter1->UpdateLargestPossibleRegion();
174 m_InputImage_1_UC = rescaleFilter1->GetOutput();
176 typename RescaleFilterType::Pointer rescaleFilter2 = RescaleFilterType::New();
177 rescaleFilter2->SetInput( this->GetInputImage2() );
178 rescaleFilter2->SetOutputMinimum( desiredMinimum );
179 rescaleFilter2->SetOutputMaximum( desiredMaximum );
180 rescaleFilter2->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
181 rescaleFilter2->SetCoordinateTolerance(m_Tol);
182 rescaleFilter2->SetDirectionTolerance(m_Tol);
183 rescaleFilter2->UpdateLargestPossibleRegion();
184 m_InputImage_2_UC = rescaleFilter2->GetOutput();
186 typename RescaleFilterType::Pointer rescaleFilter3 = RescaleFilterType::New();
187 rescaleFilter3->SetInput( this->GetInputImage3() );
188 rescaleFilter3->SetOutputMinimum( desiredMinimum );
189 rescaleFilter3->SetOutputMaximum( desiredMaximum );
190 rescaleFilter3->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits());
191 rescaleFilter3->SetCoordinateTolerance(m_Tol);
192 rescaleFilter3->SetDirectionTolerance(m_Tol);
193 rescaleFilter3->UpdateLargestPossibleRegion();
194 m_InputImage_3_UC = rescaleFilter3->GetOutput();
198 template <
typename TInputImage,
typename TMaskImage,
typename TOutput>
202 const unsigned int Dimension = 3;
203 typedef double PixelComponentType;
204 typedef itk::RGBPixel<PixelComponentType> PixelType;
205 typedef itk::Image< PixelType, Dimension > ImageType;
206 typedef itk::MahalanobisDistanceThresholdImageFunction< ImageType > FunctionType;
207 typedef FunctionType::IndexType FunctionIndexType;
216 ImageType::Pointer image = ImageType::New();
217 image->SetRegions( this->GetMask()->GetLargestPossibleRegion() );
218 image->CopyInformation( this->GetMask() );
220 itk::ImageRegionIterator<ImageType> itRGB (image, outputRegionForThread);
226 while(!itRGB.IsAtEnd())
239 FunctionType::Pointer
function = FunctionType::New();
240 FunctionType::CovarianceMatrixType Covariance( m_NbModalities, m_NbModalities );
241 Covariance.fill( 0.0 );
243 FunctionType::MeanVectorType Mean( m_NbModalities );
244 function->SetInputImage( image );
248 itk::Statistics::ChiSquareDistribution::Pointer chi = itk::Statistics::ChiSquareDistribution::New();
249 itk::SizeValueType degree = (m_GaussianModel[0])->GetMean().Size();
250 chi->SetDegreesOfFreedom(degree);
252 while(!MaskImageIt.IsAtEnd())
260 if(MaskImageIt.Get()!=0)
262 FunctionIndexType ind;
263 ind[0] = MaskImageIt.GetIndex()[0];
264 ind[1] = MaskImageIt.GetIndex()[1];
265 ind[2] = MaskImageIt.GetIndex()[2];
267 for(
unsigned int i = 0; i < m_NbTissus; i++)
269 GaussianFunctionType::MeanVectorType mean = (m_GaussianModel[i])->GetMean();
274 GaussianFunctionType::CovarianceMatrixType cov = (m_GaussianModel[i])->GetCovariance();
275 Covariance[0][0] = cov[0][0]; Covariance[1][0] = cov[1][0]; Covariance[2][0] = cov[2][0];
276 Covariance[0][1] = cov[0][1]; Covariance[1][1] = cov[1][1]; Covariance[2][1] = cov[2][1];
277 Covariance[0][2] = cov[0][2]; Covariance[1][2] = cov[1][2]; Covariance[2][2] = cov[2][2];
279 function->SetCovariance( Covariance );
280 function->SetMean( Mean );
281 double distanceD =
function->EvaluateDistanceAtIndex( ind );
282 double chiRes = chi->EvaluateCDF(distanceD);
283 double distance = 1-chiRes;
287 mahaCSFIt.Set(static_cast<OutputPixelType>(distance));
291 mahaGMIt.Set(static_cast<OutputPixelType>(distance));
295 mahaWMIt.Set(static_cast<OutputPixelType>(distance));
299 if(mahaMaxiIt.Get() < mahaCSFIt.Get())
301 mahaMaxiIt.Set(mahaCSFIt.Get());
303 if(mahaMaxiIt.Get() < mahaGMIt.Get())
305 mahaMaxiIt.Set(mahaGMIt.Get());
307 if(mahaMaxiIt.Get() < mahaWMIt.Get())
309 mahaMaxiIt.Set(mahaWMIt.Get());
311 mahaMiniIt.Set(1.0 - mahaMaxiIt.Get());
itk::ImageRegionIterator< OutputImageType > OutputIteratorType
Compute the mahalanobis images from the NABT model.
itk::ImageRegionConstIterator< MaskImageType > MaskConstIteratorType
itk::ImageRegionConstIterator< ImageTypeUC > ImageConstIteratorTypeUC
Superclass::OutputImageRegionType OutputImageRegionType