4 #include "itkImageRegionConstIterator.h" 9 template<
typename TLabelImage>
14 this->SetNumberOfRequiredInputs(2);
17 template<
typename TLabelImage>
22 itk::ThreadIdType numberOfThreads = this->GetNumberOfWorkUnits();
25 this->m_LabelSetMeasuresPerThread.resize(numberOfThreads);
28 for (itk::ThreadIdType n = 0;n < numberOfThreads;++n)
30 this->m_LabelSetMeasuresPerThread[n].clear();
34 this->m_LabelSetMeasures.clear();
39 m_fNbOfPixels = poImgIn->GetLargestPossibleRegion().GetNumberOfPixels();
42 Superclass::BeforeThreadedGenerateData();
45 template<
typename TLabelImage>
51 for (itk::ThreadIdType n = 0;n < this->GetNumberOfWorkUnits();++n)
54 for (
MapConstIterator threadIt = this->m_LabelSetMeasuresPerThread[n].begin();
55 threadIt != this->m_LabelSetMeasuresPerThread[n].end();
59 if (m_LabelSetMeasures.find((*threadIt).first) == m_LabelSetMeasures.end())
63 m_LabelSetMeasures[(*threadIt).first].
m_Source += (*threadIt).second.m_Source;
64 m_LabelSetMeasures[(*threadIt).first].m_Target += (*threadIt).second.m_Target;
65 m_LabelSetMeasures[(*threadIt).first].m_Union += (*threadIt).second.m_Union;
66 m_LabelSetMeasures[(*threadIt).first].m_TrueNegative += (*threadIt).second.m_TrueNegative;
67 m_LabelSetMeasures[(*threadIt).first].m_Intersection +=
68 (*threadIt).second.m_Intersection;
69 m_LabelSetMeasures[(*threadIt).first].m_SourceComplement +=
70 (*threadIt).second.m_SourceComplement;
71 m_LabelSetMeasures[(*threadIt).first].m_TargetComplement +=
72 (*threadIt).second.m_TargetComplement;
77 template<
typename TLabelImage>
82 itk::ImageRegionConstIterator<LabelImageType> itS(this->GetSourceImage(), outputRegionForThread);
83 itk::ImageRegionConstIterator<LabelImageType> itT(this->GetTargetImage(), outputRegionForThread);
85 unsigned int threadId = this->GetSafeThreadId();
88 for (itS.GoToBegin(), itT.GoToBegin(); !itS.IsAtEnd(); ++itS, ++itT)
94 MapIterator mapItS = m_LabelSetMeasuresPerThread[threadId].find(sourceLabel);
96 if (mapItS == m_LabelSetMeasuresPerThread[threadId].end())
100 MapIterator mapItT = m_LabelSetMeasuresPerThread[threadId].find(targetLabel);
101 if (mapItT == this->m_LabelSetMeasuresPerThread[threadId].end())
104 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_Source++;
105 m_LabelSetMeasuresPerThread[threadId][targetLabel].m_Target++;
107 if( sourceLabel == targetLabel )
109 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_Intersection++;
110 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_Union++;
114 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_Union++;
115 m_LabelSetMeasuresPerThread[threadId][targetLabel].m_Union++;
117 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_SourceComplement++;
118 m_LabelSetMeasuresPerThread[threadId][targetLabel].m_TargetComplement++;
121 if(sourceLabel == 0 && targetLabel == 0)
122 m_LabelSetMeasuresPerThread[threadId][sourceLabel].m_TrueNegative++;
125 this->SafeReleaseThreadId(threadId);
128 template<
typename TLabelImage>
136 for (
MapIterator mapIt = this->m_LabelSetMeasures.begin();
137 mapIt != this->m_LabelSetMeasures.end();++mapIt)
140 if( (*mapIt).first == itk::NumericTraits<LabelType>::Zero )
143 numerator +=
static_cast<RealType>( (*mapIt).second.m_Intersection );
144 denominator +=
static_cast<RealType>( (*mapIt).second.m_Union );
147 return numerator / denominator;
150 template<
typename TLabelImage>
155 MapIterator mapIt = this->m_LabelSetMeasures.find( label );
156 if (mapIt == this->m_LabelSetMeasures.end())
158 itkWarningMacro(
"Label " << label <<
" not found." );
163 static_cast<RealType>( (*mapIt).second.m_Intersection ) /
164 static_cast<RealType>( (*mapIt).second.m_Union );
169 template<
typename TLabelImage>
174 RealType uo = this->getUnionOverlap();
175 return 2.0 * uo / ( 1.0 + uo );
178 template<
typename TLabelImage>
183 RealType uo = this->getUnionOverlap(label);
184 return 2.0 * uo / (1.0 + uo);
187 template<
typename TLabelImage>
194 MapType orMap = this->GetLabelSetMeasures();
196 mapIt != orMap.end();++mapIt)
199 if((*mapIt).first == itk::NumericTraits<LabelType>::Zero)
202 numerator +=
static_cast<RealType>( (*mapIt).second.m_Intersection );
203 denominator +=
static_cast<RealType>( (*mapIt).second.m_Intersection ) + static_cast<RealType>( (*mapIt).second.m_TargetComplement );
206 return numerator / denominator;
209 template<
typename TLabelImage>
214 MapIterator mapIt = m_LabelSetMeasures.find(label);
215 if(mapIt == this->m_LabelSetMeasures.end())
217 itkWarningMacro(
"Label " << label <<
" not found." );
222 static_cast<RealType>((*mapIt).second.m_Intersection) /
223 (static_cast<RealType>((*mapIt).second.m_Intersection) +
static_cast<RealType>((*mapIt).second.m_TargetComplement));
228 template<
typename TLabelImage>
233 unsigned int numberOfLabels = 0;
240 mapIt = this->m_LabelSetMeasures.find(i);
243 }
while (!(mapIt == this->m_LabelSetMeasures.end()));
249 MapType orMap = this->GetLabelSetMeasures();
251 mapIt != orMap.end();++mapIt)
254 if ((*mapIt).first == itk::NumericTraits<LabelType>::Zero)
256 numerator +=
static_cast<RealType>((*mapIt).second.m_TrueNegative);
260 denominator +=
static_cast<RealType>((*mapIt).second.m_SourceComplement);
264 denominator = denominator/numberOfLabels;
265 denominator = denominator + numerator;
267 return numerator / denominator;
270 template<
typename TLabelImage>
275 MapIterator mapIt = this->m_LabelSetMeasures.find(label);
276 if(mapIt == this->m_LabelSetMeasures.end())
278 itkWarningMacro(
"Label " << label <<
" not found.");
283 (m_fNbOfPixels -
static_cast<RealType>((*mapIt).second.m_Union)) /
284 (m_fNbOfPixels -
static_cast<RealType>((*mapIt).second.m_Union) + static_cast<RealType>((*mapIt).second.m_SourceComplement));
289 template<
typename TLabelImage>
296 MapType orMap = this->GetLabelSetMeasures();
298 mapIt != orMap.end();++mapIt)
301 if ((*mapIt).first == itk::NumericTraits<LabelType>::Zero)
304 numerator +=
static_cast<RealType>((*mapIt).second.m_Intersection);
305 denominator +=
static_cast<RealType>((*mapIt).second.m_Intersection) + static_cast<RealType>((*mapIt).second.m_SourceComplement);
307 return numerator / denominator;
310 template<
typename TLabelImage>
315 MapIterator mapIt = this->m_LabelSetMeasures.find( label );
316 if (mapIt == this->m_LabelSetMeasures.end())
318 itkWarningMacro(
"Label " << label <<
" not found.");
323 static_cast<RealType>((*mapIt).second.m_Intersection) /
324 (static_cast<RealType>((*mapIt).second.m_Intersection) +
static_cast<RealType>((*mapIt).second.m_SourceComplement));
329 template<
typename TLabelImage>
334 unsigned int numberOfLabels = 0;
340 mapIt = this->m_LabelSetMeasures.find(i);
343 }
while (!(mapIt == this->m_LabelSetMeasures.end()));
349 MapType orMap = this->GetLabelSetMeasures();
351 mapIt != orMap.end();++mapIt)
354 if ((*mapIt).first == itk::NumericTraits<LabelType>::Zero)
356 numerator +=
static_cast<RealType>((*mapIt).second.m_TrueNegative);
360 denominator +=
static_cast<RealType>((*mapIt).second.m_TargetComplement);
363 denominator = denominator/numberOfLabels;
364 denominator = numerator + denominator;
365 return numerator / denominator;
368 template<
typename TLabelImage>
373 MapIterator mapIt = this->m_LabelSetMeasures.find(label);
374 if (mapIt == this->m_LabelSetMeasures.end())
376 itkWarningMacro(
"Label " << label <<
" not found.");
381 (m_fNbOfPixels -
static_cast<RealType>( (*mapIt).second.m_Union )) /
382 (m_fNbOfPixels -
static_cast<RealType>( (*mapIt).second.m_Union ) + static_cast<RealType>( (*mapIt).second.m_TargetComplement ));
387 template<
typename TLabelImage>
393 for (
MapIterator mapIt = this->m_LabelSetMeasures.begin();
394 mapIt != this->m_LabelSetMeasures.end();++mapIt)
397 if((*mapIt).first == itk::NumericTraits<LabelType>::Zero)
402 numerator += Vt - Vgt;
403 denominator +=
static_cast<RealType>((*mapIt).second.m_Target);
406 return numerator / denominator;
409 template<
typename TLabelImage>
415 MapIterator mapIt = this->m_LabelSetMeasures.find(label);
416 if(mapIt == this->m_LabelSetMeasures.end())
418 itkWarningMacro(
"Label " << label <<
" not found." );
424 numerator = Vt - Vgt;
425 denominator =
static_cast<RealType>((*mapIt).second.m_Target);
426 return numerator / denominator;
TLabelImage::PixelType LabelType
void BeforeThreadedGenerateData() ITK_OVERRIDE
RealType getUnionOverlap()
RealType getMeanOverlap()
RealType getSensitivity()
SegmentationMeasuresImageFilter()
void AfterThreadedGenerateData() ITK_OVERRIDE
MapType::const_iterator MapConstIterator
MapType::iterator MapIterator
TLabelImage::RegionType RegionType
RealType getRelativeVolumeError()
TLabelImage LabelImageType
RealType getSpecificity()
std::map< LabelType, SegPerfLabelSetMeasures > MapType
void DynamicThreadedGenerateData(const RegionType &) ITK_OVERRIDE
itk::NumericTraits< LabelType >::RealType RealType