Orfeo Toolbox  3.16
itkSampleClassifier.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSampleClassifier.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-04 19:29:53 $
7  Version: $Revision: 1.17 $
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 #ifndef __itkSampleClassifier_txx
18 #define __itkSampleClassifier_txx
19 
20 #include "itkSampleClassifier.h"
21 
22 namespace itk {
23 namespace Statistics {
24 
25 template< class TSample >
28 {
29  m_Sample = 0;
30  m_Output = OutputType::New();
31 }
32 
33 template< class TSample >
34 void
36 ::PrintSelf(std::ostream& os, Indent indent) const
37 {
38  Superclass::PrintSelf(os,indent);
39 
40  os << indent << "Sample: ";
41  if ( m_Sample != 0 )
42  {
43  os << m_Sample << std::endl;
44  }
45  else
46  {
47  os << "not set." << std::endl;
48  }
49 
50  os << indent << "Output: " << m_Output << std::endl;
51 }
52 
53 template< class TSample >
54 void
56 ::SetSample(const TSample* sample)
57 {
58  if ( m_Sample != sample )
59  {
60  m_Sample = sample;
61  m_Output->SetSample(sample);
62  }
63 }
64 
65 template< class TSample >
66 const TSample*
68 ::GetSample() const
69 {
70  return m_Sample;
71 }
72 
73 template< class TSample >
74 void
77 {
78  m_ClassLabels = labels;
79 }
80 
81 template< class TSample >
82 void
85 {
86  unsigned int i;
87  typename TSample::ConstIterator iter = this->GetSample()->Begin();
88  typename TSample::ConstIterator end = this->GetSample()->End();
89  typename TSample::MeasurementVectorType measurements;
90 
91  m_Output->Resize( this->GetSample()->Size() );
92  std::vector< double > discriminantScores;
93  unsigned int numberOfClasses = this->GetNumberOfClasses();
94  discriminantScores.resize(numberOfClasses);
95  unsigned int classLabel;
96  m_Output->SetNumberOfClasses(numberOfClasses);
98  this->GetDecisionRule();
99 
100  if ( m_ClassLabels.size() != this->GetNumberOfMembershipFunctions() )
101  {
102  while (iter != end)
103  {
104  measurements = iter.GetMeasurementVector();
105  for (i = 0; i < numberOfClasses; i++)
106  {
107  discriminantScores[i] =
108  (this->GetMembershipFunction(i))->Evaluate(measurements);
109  }
110  classLabel = rule->Evaluate(discriminantScores);
111  m_Output->AddInstance(classLabel, iter.GetInstanceIdentifier());
112  ++iter;
113  }
114  }
115  else
116  {
117  while (iter != end)
118  {
119  measurements = iter.GetMeasurementVector();
120  for (i = 0; i < numberOfClasses; i++)
121  {
122  discriminantScores[i] =
123  (this->GetMembershipFunction(i))->Evaluate(measurements);
124  }
125  classLabel = rule->Evaluate(discriminantScores);
126  m_Output->AddInstance(m_ClassLabels[classLabel],
127  iter.GetInstanceIdentifier());
128  ++iter;
129  }
130  }
131 }
132 
133 template< class TSample >
137 {
138  return m_Output;
139 }
140 
141 } // end of namespace Statistics
142 } // end of namespace itk
143 
144 #endif

Generated at Sun May 19 2013 00:04:20 for Orfeo Toolbox with doxygen 1.8.3.1