21 #ifndef otbSOMClassifier_hxx
22 #define otbSOMClassifier_hxx
32 template <
class TSample,
class TSOMMap,
class TLabel>
35 this->SetNumberOfRequiredInputs(1);
37 this->SetNthInput(0, sommap.GetPointer());
38 m_Sample = SampleType::New();
42 this->SetNthOutput(0, outputPtr.GetPointer());
45 template <
class TSample,
class TSOMMap,
class TLabel>
48 return dynamic_cast<OutputType*
>(this->itk::ProcessObject::GetOutput(0));
54 template <
class TSample,
class TSOMMap,
class TLabel>
57 return dynamic_cast<SOMMapType*
>(this->itk::ProcessObject::GetInput(0));
63 template <
class TSample,
class TSOMMap,
class TLabel>
66 this->itk::ProcessObject::SetNthInput(0,
const_cast<SOMMapType*
>(sommap));
72 template <
class TSample,
class TSOMMap,
class TLabel>
75 Superclass::PrintSelf(os, indent);
81 template <
class TSample,
class TSOMMap,
class TLabel>
84 typename OutputType::Pointer outputPtr = this->GetOutput();
85 outputPtr->SetSample(this->GetSample());
87 typename SOMMapType::SizeType size = this->GetMap()->GetLargestPossibleRegion().GetSize();
88 unsigned int numberOfClasses = 1;
89 for (
unsigned int i = 0; i < SOMMapType::ImageDimension; ++i)
91 numberOfClasses *= size[i];
93 outputPtr->SetNumberOfClasses(numberOfClasses);
96 typename TSample::Iterator iter = this->GetSample()->Begin();
97 typename TSample::Iterator end = this->GetSample()->End();
99 typename OutputType::ConstIterator iterO = outputPtr->Begin();
100 typename OutputType::ConstIterator endO = outputPtr->End();
101 typename TSample::MeasurementVectorType measurements;
103 typename SOMMapType::IndexType index;
108 while (iter != end && iterO != endO)
111 measurements = iter.GetMeasurementVector();
112 index = somMap->GetWinner(measurements);
114 outputPtr->AddInstance(classLabel, iterO.GetInstanceIdentifier());