| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkMahalanobisDistanceThresholdImageFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:41 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
DEF |
#ifndef _itkMahalanobisDistanceThresholdImageFunction_txx |
| 18 |
DEF |
#define _itkMahalanobisDistanceThresholdImageFunction_txx |
| 19 |
|
|
| 20 |
|
#include "itkMahalanobisDistanceThresholdImageFunction.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
template <class TInputImage, class TCoordRep> |
| 26 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 27 |
|
::MahalanobisDistanceThresholdImageFunction() |
| 28 |
|
{ |
| 29 |
|
m_Threshold = NumericTraits<double>::Zero; |
| 30 |
|
m_MahalanobisDistanceMembershipFunction = |
| 31 |
IND |
**********MahalanobisDistanceFunctionType::New(); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
template <class TInputImage, class TCoordRep> |
| 36 |
|
void |
| 37 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 38 |
|
::SetMean(const MeanVectorType & mean) |
| 39 |
|
{ |
| 40 |
|
m_MahalanobisDistanceMembershipFunction->SetMean( mean ); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
|
| 44 |
EML |
|
| 45 |
|
template <class TInputImage, class TCoordRep> |
| 46 |
|
void |
| 47 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 48 |
|
::SetCovariance(const CovarianceMatrixType & covariance) |
| 49 |
|
{ |
| 50 |
|
m_MahalanobisDistanceMembershipFunction->SetCovariance( covariance ); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
EML |
|
| 55 |
|
template <class TInputImage, class TCoordRep> |
| 56 |
|
const typename |
| 57 |
LEN |
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep>::MeanVectorType & |
| 58 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 59 |
|
::GetMean() const |
| 60 |
|
{ |
| 61 |
|
return m_MahalanobisDistanceMembershipFunction->GetMean(); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
template <class TInputImage, class TCoordRep> |
| 66 |
|
const typename |
| 67 |
LEN |
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep>::CovarianceMatrixType & |
| 68 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 69 |
|
::GetCovariance() const |
| 70 |
|
{ |
| 71 |
|
return m_MahalanobisDistanceMembershipFunction->GetCovariance(); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 75 |
EML |
|
| 76 |
|
template <class TInputImage, class TCoordRep> |
| 77 |
|
bool |
| 78 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 79 |
|
::Evaluate( const PointType& point ) const |
| 80 |
|
{ |
| 81 |
|
IndexType index; |
| 82 |
|
this->ConvertPointToNearestIndex( point, index ); |
| 83 |
|
return ( this->EvaluateAtIndex( index ) ); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
EML |
|
| 88 |
EML |
|
| 89 |
|
template <class TInputImage, class TCoordRep> |
| 90 |
|
bool |
| 91 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 92 |
|
::EvaluateAtContinuousIndex( const ContinuousIndexType & index ) const |
| 93 |
|
{ |
| 94 |
|
IndexType nindex; |
| 95 |
|
this->ConvertContinuousIndexToNearestIndex (index, nindex); |
| 96 |
|
return this->EvaluateAtIndex(nindex); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
EML |
|
| 101 |
|
template <class TInputImage, class TCoordRep> |
| 102 |
|
bool |
| 103 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 104 |
|
::EvaluateAtIndex( const IndexType & index ) const |
| 105 |
|
{ |
| 106 |
|
double mahalanobisDistance = |
| 107 |
IND |
****m_MahalanobisDistanceMembershipFunction->Evaluate( |
| 108 |
|
this->GetInputImage()->GetPixel( index ) ); |
| 109 |
|
return ( sqrt( mahalanobisDistance ) <= m_Threshold ); |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
EML |
|
| 114 |
|
template <class TInputImage, class TCoordRep> |
| 115 |
|
double |
| 116 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 117 |
|
::EvaluateDistance( const PointType& point ) const |
| 118 |
|
{ |
| 119 |
|
IndexType index; |
| 120 |
|
this->ConvertPointToNearestIndex( point, index ); |
| 121 |
|
const double mahalanobisDistance = this->EvaluateDistanceAtIndex( index ); |
| 122 |
|
return mahalanobisDistance; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
template <class TInputImage, class TCoordRep> |
| 127 |
|
double |
| 128 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 129 |
|
::EvaluateDistanceAtIndex( const IndexType& index ) const |
| 130 |
|
{ |
| 131 |
|
const double mahalanobisDistanceSquared = |
| 132 |
IND |
****m_MahalanobisDistanceMembershipFunction->Evaluate( |
| 133 |
|
this->GetInputImage()->GetPixel( index ) ); |
| 134 |
|
|
| 135 |
|
const double mahalanobisDistance = sqrt( mahalanobisDistanceSquared ); |
| 136 |
|
|
| 137 |
|
return mahalanobisDistance; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
EML |
|
| 142 |
EML |
|
| 143 |
EML |
|
| 144 |
|
template <class TInputImage, class TCoordRep> |
| 145 |
|
void |
| 146 |
|
MahalanobisDistanceThresholdImageFunction<TInputImage,TCoordRep> |
| 147 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 148 |
|
{ |
| 149 |
|
Superclass::PrintSelf( os, indent ); |
| 150 |
|
|
| 151 |
|
os << indent << "Threshold: " << m_Threshold << std::endl; |
| 152 |
LEN |
os << indent << "MahalanobisDistanceMembershipFunction: " << m_MahalanobisDistanceMembershipFunction << std::endl; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
} // end namespace itk |
| 156 |
|
|
| 157 |
|
#endif |
| 158 |
|
|