18 #ifndef __otbSOMImageClassificationFilter_txx
19 #define __otbSOMImageClassificationFilter_txx
23 #include "itkNumericTraits.h"
30 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
34 this->SetNumberOfInputs(2);
35 this->SetNumberOfRequiredInputs(1);
36 m_DefaultLabel = itk::NumericTraits<LabelType>::ZeroValue();
39 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
47 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
53 if (this->GetNumberOfInputs() < 2)
60 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
67 itkGenericExceptionMacro(<<
"No model for classification");
71 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
86 InputIteratorType inIt(inputPtr, outputRegionForThread);
88 MaskIteratorType maskIt;
91 maskIt = MaskIteratorType(inputMaskPtr, outputRegionForThread);
94 unsigned int maxDimension = m_Map->GetNumberOfComponentsPerPixel();
95 unsigned int sampleSize = std::min(inputPtr->GetNumberOfComponentsPerPixel(),
97 bool validPoint =
true;
99 for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt)
103 validPoint = maskIt.Get() > 0;
109 sample.SetSize(sampleSize);
110 sample.Fill(itk::NumericTraits<ValueType>::ZeroValue());
111 for (
unsigned int i = 0; i < sampleSize; ++i)
113 sample[i] = inIt.Get()[i];
115 listSample->PushBack(sample);
119 classifier->SetMap(m_Map);
120 classifier->SetSample(listSample);
121 classifier->Update();
124 typename ClassifierType::OutputType::ConstIterator sampleIter = membershipSample->Begin();
125 typename ClassifierType::OutputType::ConstIterator sampleLast = membershipSample->End();
127 OutputIteratorType outIt(outputPtr, outputRegionForThread);
131 while (!outIt.IsAtEnd() && (sampleIter != sampleLast))
133 outIt.Set(m_DefaultLabel);
145 while (!outIt.IsAtEnd() && (sampleIter != sampleLast))
149 validPoint = maskIt.Get() > 0;
154 outIt.Set(sampleIter.GetClassLabel());
163 template <
class TInputImage,
class TOutputImage,
class TSOMMap,
class TMaskImage>
168 Superclass::PrintSelf(os, indent);