00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freImageDifferenceSOMetric_txx
00023 #define __freImageDifferenceSOMetric_txx
00024
00025 #include "freImageDifferenceSOMetric.h"
00026 #include "freGenericSetupToImageAdaptor.h"
00027 #include "freImageSampleCharacteristicsCalculator.h"
00028 #include "freSessionProcessor.h"
00029
00030 #include "freImageIO.h"
00031 #include "itkNumericTraits.h"
00032 #include "itkAbsoluteValueDifferenceImageFilter.h"
00033
00034 #include <time.h>
00035
00036 namespace FREE
00037 {
00038
00039 template <unsigned int VImageDimension>
00040 void
00041 ImageDifferenceSOMetric<VImageDimension>::
00042 SetReferenceImagePath(const IDPath& path)
00043 {
00044 itkDebugMacro("setting ReferenceImagePath to " << path.ToStr() );
00045 this->m_ReferenceImagePath = path;
00046 this->Modified(); \
00047 };
00048
00049 template <unsigned int VImageDimension>
00050 void
00051 ImageDifferenceSOMetric<VImageDimension>::
00052 SetResultImagePath(const IDPath& path)
00053 {
00054 itkDebugMacro("setting ResultImagePath to " << path.ToStr() );
00055 this->m_ResultImagePath = path;
00056 this->Modified(); \
00057 };
00058
00059 template <unsigned int VImageDimension>
00060 ImageDifferenceSOMetric<VImageDimension>::
00061 ImageDifferenceSOMetric()
00062 {
00063 m_ResultImagePath.Reset();
00064 m_ReferenceImagePath.Reset();
00065 };
00066
00067 template <unsigned int VImageDimension>
00068 void
00069 ImageDifferenceSOMetric<VImageDimension>::
00070 InitializeValueComputation() const
00071 {
00072 m_dErrorMean = 0.0;
00073 m_dErrorDev = 0.0;
00074 m_dMinError = itk::NumericTraits< double >::max();
00075 m_dMaxError = 0.0;
00076 m_lFailedProcessings = 0;
00077
00078 m_dImageErrorMean = 0.0;
00079 m_dImageErrorDev = 0.0;
00080 m_dMinImageError = itk::NumericTraits< double >::max();
00081 m_dMaxImageError = 0.0;
00082
00083 m_dDurMean = 0.0;
00084 m_dDurDev = 0.0;
00085 m_dMinDur = itk::NumericTraits< double >::max();
00086 m_dMaxDur = 0.0;
00087
00088 m_Errors.clear();
00089 m_Vars.clear();
00090 m_Samplesize.clear();
00091 m_Durations.clear();
00092 };
00093
00094 template <unsigned int VImageDimension>
00095 void
00096 ImageDifferenceSOMetric<VImageDimension>::
00097 InitializeMonitor(MonitorType& monitor) const
00098 {
00099
00100 };
00101
00102 template <unsigned int VImageDimension>
00103 void
00104 ImageDifferenceSOMetric<VImageDimension>::
00105 InitializeThread(ThreadType& thread) const
00106 {
00107 thread.SetResultImagePath(this->m_ResultImagePath);
00108 thread.SetReferenceImagePath(this->m_ReferenceImagePath);
00109 };
00110
00111 template <unsigned int VImageDimension>
00112 typename ImageDifferenceSOMetric<VImageDimension>::DecomposedMeasureType
00113 ImageDifferenceSOMetric<VImageDimension>::
00114 ComputeMeasure(MonitorType& monitor) const
00115 {
00116
00117 this->m_lFailedProcessings = monitor.GetFailureCount();
00118
00119 typename MonitorType::AdaptationIDListType evaluations = monitor.GetListOfEvaluatedAdaptations();
00120
00121 for (typename MonitorType::AdaptationIDListType::const_iterator pos = evaluations.begin(); pos != evaluations.end(); ++pos)
00122 {
00123 EvaluationResultType results;
00124 monitor.GetAdaptationResults(*pos,results);
00125
00126 if (this->m_dMinError > results.GetMinError()) this->m_dMinError = results.GetMinError();
00127 if (this->m_dMaxError < results.GetMaxError()) this->m_dMaxError = results.GetMaxError();
00128
00129 this->m_Errors.push_back(results.GetError());
00130 this->m_Vars.push_back(results.GetVariance());
00131 this->m_ImageErrors.push_back(results.GetImageError());
00132 this->m_Samplesize.push_back(results.GetSamplesize());
00133 this->m_Durations.push_back(results.GetDuration());
00134 }
00135
00136
00137 unsigned long lTotalSamples = 0;
00138
00139 try
00140 {
00141 for (unsigned int iIndex=0; iIndex<m_Errors.size(); iIndex++)
00142 {
00143 m_dErrorMean += m_Errors[iIndex] * m_Samplesize[iIndex];
00144 m_dErrorDev += m_Vars[iIndex] * (m_Samplesize[iIndex]-1);
00145 lTotalSamples += m_Samplesize[iIndex];
00146 }
00147
00148 if (m_Errors.size()==0) m_dMinError = 0.0;
00149
00150 if (lTotalSamples>0) m_dErrorMean /= lTotalSamples;
00151 if (lTotalSamples>1) m_dErrorDev /= lTotalSamples-1;
00152
00153 m_dErrorDev = sqrt(m_dErrorDev);
00154 }
00155 catchAllNPassMacro("Unkown error while computing the pixel error.");
00156
00157 try
00158 {
00159
00160 for (unsigned int iIndex=0; iIndex<m_ImageErrors.size(); iIndex++)
00161 {
00162 m_dImageErrorMean += m_ImageErrors[iIndex];
00163 if (m_ImageErrors[iIndex]<m_dMinImageError) m_dMinImageError = m_ImageErrors[iIndex];
00164 else if (m_ImageErrors[iIndex]>m_dMaxImageError) m_dMaxImageError = m_ImageErrors[iIndex];
00165 }
00166 if (m_ImageErrors.size()!=0) m_dImageErrorMean /= m_ImageErrors.size();
00167
00168 if (m_ImageErrors.size()>1)
00169 {
00170 for (unsigned int iIndex=0; iIndex<m_ImageErrors.size(); iIndex++)
00171 {
00172 m_dImageErrorDev += (m_ImageErrors[iIndex]-m_dImageErrorMean)*(m_ImageErrors[iIndex]-m_dImageErrorMean);
00173 }
00174 m_dImageErrorDev = sqrt(m_dImageErrorDev/(m_ImageErrors.size()-1));
00175 }
00176 }
00177 catchAllNPassMacro("Unkown error while computing the image error.");
00178
00179 try
00180 {
00181
00182 for (unsigned int iIndex=0; iIndex<m_Durations.size(); iIndex++)
00183 {
00184 m_dDurMean += m_Durations[iIndex];
00185 if (m_Durations[iIndex]< m_dMinDur) m_dMinDur = m_Durations[iIndex];
00186 else if (m_Durations[iIndex]> m_dMaxDur) m_dMaxDur = m_Durations[iIndex];
00187 }
00188
00189 if (m_Durations.size()==0) m_dMinDur = 0.0;
00190 if (m_Durations.size()>0) m_dDurMean /= m_Durations.size();
00191
00192 if (m_Durations.size()>1)
00193 {
00194 for (unsigned int iIndex=0; iIndex<m_Durations.size(); iIndex++)
00195 {
00196 m_dDurDev += (m_Durations[iIndex] - m_dDurMean)*(m_Durations[iIndex] - m_dDurMean);
00197 }
00198 m_dDurDev = sqrt(m_dDurDev / (m_Durations.size()-1));
00199 }
00200 }
00201 catchAllNPassMacro("Unkown error while computing the duration.");
00202
00203
00204 DecomposedMeasureType results(13);
00205
00206 results.SetElement(0,m_dErrorMean);
00207 results.SetElement(1,m_dErrorDev);
00208 results.SetElement(2,m_dMinError);
00209 results.SetElement(3,m_dMaxError);
00210 results.SetElement(4,m_dImageErrorMean);
00211 results.SetElement(5,m_dImageErrorDev);
00212 results.SetElement(6,m_dMinImageError);
00213 results.SetElement(7,m_dMaxImageError);
00214 results.SetElement(8,m_lFailedProcessings);
00215 results.SetElement(9,m_dDurMean);
00216 results.SetElement(10,m_dDurDev);
00217 results.SetElement(11,m_dMinDur);
00218 results.SetElement(12,m_dMaxDur);
00219
00220 return results;
00221 };
00222
00223 }
00224
00225 #endif