00001 /*========================================================================= 00002 00003 Program: F.R.E.E. - flexible registration evaluation engine 00004 Version: v.1.0.0 00005 Date: $Date: 2006/09/01 12:00:00 $ 00006 Module: $RCSfile: freImageClassificationSOMetricThread.txx,v $ 00007 Language: C++ 00008 00009 00010 00011 Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics, 00012 Institute for Medical Biometry and Informatics, University of Heidelberg, 00013 Germany). All rights reserved. 00014 See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm 00015 for details. 00016 00017 This software is distributed WITHOUT ANY WARRANTY; without even 00018 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00019 PURPOSE. See the above copyright notices for more information. 00020 00021 =========================================================================*/ 00022 #ifndef __freImageClassificationSOMetricThread_txx 00023 #define __freImageClassificationSOMetricThread_txx 00024 00025 #include "freImageClassificationSOMetricThread.h" 00026 00027 #include "freSessionProcessor.h" 00028 #include "freImageSampleCharacteristicsCalculator.h" 00029 00030 #include "itkNumericTraits.h" 00031 #include "itkAbsoluteValueDifferenceImageFilter.h" 00032 00033 namespace FREE 00034 { 00035 00036 template <unsigned int VImageDimension> 00037 void 00038 ImageClassificationSOMetricThread<VImageDimension>:: 00039 SetResultImagePath(const IDPath& path) 00040 { 00041 this->LockExecutionMutex(); 00042 this->m_ResultImagePath = path; 00043 this->UnlockExecutionMutex(); 00044 }; 00045 00046 template <unsigned int VImageDimension> 00047 const IDPath& 00048 ImageClassificationSOMetricThread<VImageDimension>:: 00049 GetResultImagePath() const {return m_ResultImagePath;}; 00050 00051 template <unsigned int VImageDimension> 00052 void 00053 ImageClassificationSOMetricThread<VImageDimension>:: 00054 SetReferenceImagePath(const IDPath& path) 00055 { 00056 this->LockExecutionMutex(); 00057 this->m_ReferenceImagePath = path; 00058 this->UnlockExecutionMutex(); 00059 }; 00060 00061 template <unsigned int VImageDimension> 00062 const IDPath& 00063 ImageClassificationSOMetricThread<VImageDimension>:: 00064 GetReferenceImagePath() const {return m_ReferenceImagePath;}; 00065 00066 template <unsigned int VImageDimension> 00067 void 00068 ImageClassificationSOMetricThread<VImageDimension>:: 00069 SetLowerClassThreshold(const double& dLower) 00070 { 00071 this->LockExecutionMutex(); 00072 this->m_dLower = dLower; 00073 this->UnlockExecutionMutex(); 00074 }; 00075 00076 template <unsigned int VImageDimension> 00077 const double& 00078 ImageClassificationSOMetricThread<VImageDimension>:: 00079 GetLowerClassThreshold() const {return m_dLower;}; 00080 00081 template <unsigned int VImageDimension> 00082 void 00083 ImageClassificationSOMetricThread<VImageDimension>:: 00084 SetUpperClassThreshold(const double& dUpper) 00085 { 00086 this->LockExecutionMutex(); 00087 this->m_dUpper = dUpper; 00088 this->UnlockExecutionMutex(); 00089 }; 00090 00091 template <unsigned int VImageDimension> 00092 const double& 00093 ImageClassificationSOMetricThread<VImageDimension>:: 00094 GetUpperClassThreshold() const {return m_dUpper;}; 00095 00096 template <unsigned int VImageDimension> 00097 ImageClassificationSOMetricThread<VImageDimension>:: 00098 ImageClassificationSOMetricThread() 00099 { 00100 m_ReferenceImagePath.Reset(); 00101 m_ResultImagePath.Reset(); 00102 m_dUpper = 0; 00103 m_dLower = 0; 00104 }; 00105 00106 template <unsigned int VImageDimension> 00107 ImageClassificationSOMetricThread<VImageDimension>:: 00108 ~ImageClassificationSOMetricThread() {}; 00109 00110 template <unsigned int VImageDimension> 00111 bool 00112 ImageClassificationSOMetricThread<VImageDimension>:: 00113 ProcessSetup(Setup* pAdaptationSetup) throw() 00114 { 00115 bool result = false; 00116 00117 ControllerCentral::AddOnProgressEvent(this->m_EvaluatedSessionProgressEvent); 00118 00119 SessionProcessor processor; 00120 00121 try 00122 { 00123 00124 processor.SetSetup(pAdaptationSetup); 00125 processor.DefineOutput("resultImage", this->m_ResultImagePath); 00126 00127 processor.InitializeSession(); 00128 00129 this->m_EvaluatedSessionProgressEvent->SetACR(processor.GetSessionInfo()->GetSessionCache()); 00130 00131 clock_t start = clock(); 00132 00133 typename ImageType::Pointer smpResult = processor.GetCastedOutput<ImageType>("resultImage"); 00134 00135 clock_t stop = clock(); 00136 double dDuration = (stop-start) / (CLOCKS_PER_SEC/10); //convert clocks to thenth second 00137 00138 //evaluating registration result 00139 typename ImageType::Pointer smpReference = NULL; 00140 00141 if (m_ReferenceImagePath.IsEmpty()) throwExceptionMacro("Error: Reference image path is null, but should be used to measure the adaptation. Ensure correct initialisation of the metric."); 00142 try 00143 { 00144 typename SessionAccessor::GenericMediaPointer smpGenReference = SessionAccessor::GetMedia(m_ReferenceImagePath, processor.GetSessionInfo()); 00145 smpReference = static_cast<ImageType*>(smpGenReference.GetPointer()); 00146 } 00147 catchAllNPassMacro("Error: cannot retrieve reference image. Ensure correct IDPath. Used path: "<<m_ReferenceImagePath.ToStr()); 00148 00149 if (smpResult->GetLargestPossibleRegion() != smpReference->GetLargestPossibleRegion()) throwExceptionMacro("Error: Reference and result image must have the same largest possible region! reference: " <<smpReference->GetLargestPossibleRegion()<<" result: "<<smpResult->GetLargestPossibleRegion()); 00150 00151 EvaluateResult(smpResult, smpReference); 00152 m_Results.SetDuration((unsigned long)dDuration); 00153 00154 result = true; 00155 } 00156 catch( FREE::ExceptionBase & err ) 00157 { 00158 this->m_FailureComment = std::string(err.what()); 00159 } 00160 catch(...) 00161 { 00162 this->m_FailureComment = "unkown error"; 00163 } 00164 00165 processor.ResetSession(); 00166 00167 ControllerCentral::RemoveOnProgressEvent(m_EvaluatedSessionProgressEvent); 00168 00169 return result; 00170 }; 00171 00172 template <unsigned int VImageDimension> 00173 void 00174 ImageClassificationSOMetricThread<VImageDimension>:: 00175 EvaluateResult(ImageType* pResultImage, ImageType* pReferenceImage) 00176 { 00177 unsigned long lTP = 0; 00178 unsigned long lFP = 0; 00179 unsigned long lTN = 0; 00180 unsigned long lFN = 0; 00181 00182 typedef itk::ImageRegionConstIterator<ImageType> ImageIterator; 00183 ImageIterator resultIt(pResultImage,pResultImage->GetBufferedRegion()); 00184 ImageIterator referenceIt(pReferenceImage,pReferenceImage->GetBufferedRegion()); 00185 00186 referenceIt.GoToBegin(); 00187 for ( resultIt.GoToBegin(); !resultIt.IsAtEnd(); ++resultIt, ++referenceIt ) 00188 { 00189 typename ImageType::PixelType resultPixel = resultIt.Get(); 00190 typename ImageType::PixelType referencePixel = referenceIt.Get(); 00191 00192 bool referenceClass = (referencePixel>=m_dLower) && (referencePixel<=m_dUpper); 00193 bool resultClass = (resultPixel>=m_dLower) && (resultPixel<=m_dUpper); 00194 00195 if (resultClass) 00196 { 00197 if (referenceClass) lTP++; 00198 else lFP++; 00199 } 00200 else 00201 { 00202 if (!referenceClass) lTN++; 00203 else lFN++; 00204 } 00205 } 00206 00207 this->m_Results.SetTP(lTP); 00208 this->m_Results.SetFP(lFP); 00209 this->m_Results.SetTN(lTN); 00210 this->m_Results.SetFN(lFN); 00211 }; 00212 00213 } // end namespace FREE 00214 00215 #endif
1.5.3 written by Dimitri van Heesch,
© 1997-2000