Orfeo Toolbox  3.16
itkSampleClassifierWithMask.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSampleClassifierWithMask.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-04 19:29:54 $
7  Version: $Revision: 1.9 $
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 __itkSampleClassifierWithMask_txx
18 #define __itkSampleClassifierWithMask_txx
19 
21 
22 namespace itk {
23 namespace Statistics {
24 
25 template< class TSample, class TMaskSample >
28 {
29  m_OtherClassLabel = 0;
30  m_Mask = 0;
31 }
32 
33 template< class TSample, class TMaskSample >
34 void
36 ::PrintSelf(std::ostream& os, Indent indent) const
37 {
38  Superclass::PrintSelf(os,indent);
39 
40  os << indent << "Mask: ";
41  if ( m_Mask.IsNotNull() )
42  {
43  os << m_Mask << std::endl;
44  }
45  else
46  {
47  os << "not set." << std::endl;
48  }
49 
50  os << indent << "SelectedClassLabels: ";
51  for ( unsigned int i = 0; i < m_SelectedClassLabels.size(); ++i )
52  {
53  os << " " << m_SelectedClassLabels[i];
54  }
55  os << std::endl;
56  os << indent << "OtherClassLabel: " << m_OtherClassLabel << std::endl;
57 }
58 
59 template< class TSample, class TMaskSample >
60 void
62 ::SetMask(TMaskSample* mask)
63 {
64  if ( m_Mask != mask )
65  {
66  m_Mask = mask;
67  }
68 }
69 
70 template< class TSample, class TMaskSample >
71 void
74 {
75  unsigned int i;
76  typename TSample::ConstIterator iter = this->GetSample()->Begin();
77  typename TSample::ConstIterator end = this->GetSample()->End();
78  typename TSample::MeasurementVectorType measurements;
79 
80  typename TMaskSample::Iterator m_iter = this->GetMask()->Begin();
81 
82  OutputType* output = this->GetOutput();
83  output->Resize(this->GetSample()->Size());
84  std::vector< double > discriminantScores;
85  unsigned int numberOfClasses = this->GetNumberOfClasses();
86  discriminantScores.resize(numberOfClasses);
87  output->SetNumberOfClasses(numberOfClasses + 1);
88  unsigned int classLabel;
90  this->GetDecisionRule();
91  typename Superclass::ClassLabelVectorType classLabels =
92  this->GetMembershipFunctionClassLabels();
93 
94  if ( this->GetMask()->Size() != this->GetSample()->Size() )
95  {
96  itkExceptionMacro("The sizes of the mask sample and the input sample do not match.");
97  }
98 
99  if ( classLabels.size() != this->GetNumberOfMembershipFunctions() )
100  {
101  while (iter != end)
102  {
103  measurements = iter.GetMeasurementVector();
104  if ( std::find(m_SelectedClassLabels.begin(),
105  m_SelectedClassLabels.end(),
106  m_iter.GetMeasurementVector()[0]) !=
107  m_SelectedClassLabels.end() )
108  {
109  for (i = 0; i < numberOfClasses; i++)
110  {
111  discriminantScores[i] =
112  (this->GetMembershipFunction(i))->Evaluate(measurements);
113  }
114  classLabel = rule->Evaluate(discriminantScores);
115  }
116  else
117  {
118  classLabel = m_OtherClassLabel;
119  }
120  output->AddInstance(classLabel, iter.GetInstanceIdentifier());
121  ++iter;
122  ++m_iter;
123  }
124  }
125  else
126  {
127  while (iter != end)
128  {
129  measurements = iter.GetMeasurementVector();
130  if ( std::find(m_SelectedClassLabels.begin(),
131  m_SelectedClassLabels.end(),
132  m_iter.GetMeasurementVector()[0]) !=
133  m_SelectedClassLabels.end() )
134  {
135  for (i = 0; i < numberOfClasses; i++)
136  {
137  discriminantScores[i] =
138  (this->GetMembershipFunction(i))->Evaluate(measurements);
139  }
140  classLabel = rule->Evaluate(discriminantScores);
141  output->AddInstance(classLabels[classLabel],
142  iter.GetInstanceIdentifier());
143  }
144  else
145  {
146  output->AddInstance(m_OtherClassLabel,
147  iter.GetInstanceIdentifier());
148  }
149  ++iter;
150  ++m_iter;
151  }
152  }
153 }
154 
155 } // end of namespace Statistics
156 } // end of namespace itk
157 
158 #endif

Generated at Sun Feb 3 2013 00:03:55 for Orfeo Toolbox with doxygen 1.8.1.1