22 #ifndef otbSOMWithMissingValue_hxx
23 #define otbSOMWithMissingValue_hxx
27 #include "itkNumericTraits.h"
28 #include "itkNeighborhoodIterator.h"
33 template <
class TListSample,
class TMap,
class TSOMLearningBehaviorFunctor,
class TSOMNeighborhoodBehaviorFunctor>
38 template <
class TListSample,
class TMap,
class TSOMLearningBehaviorFunctor,
class TSOMNeighborhoodBehaviorFunctor>
50 template <
class TListSample,
class TMap,
class TSOMLearningBehaviorFunctor,
class TSOMNeighborhoodBehaviorFunctor>
58 IndexType position = map->GetWinner(sample);
62 typedef typename MapType::Superclass ImageMapType;
63 typedef itk::NeighborhoodIterator<ImageMapType> NeighborhoodIteratorType;
64 typename MapType::RegionType mapRegion = map->GetLargestPossibleRegion();
65 NeighborhoodIteratorType it(radius, map, mapRegion);
70 SizeType mapSize = mapRegion.GetSize();
74 it.SetLocation(position);
76 for (
unsigned int i = 0; i < it.Size(); ++i)
78 typename NeighborhoodIteratorType::OffsetType offset = it.GetOffset(i);
81 double theDistance = itk::NumericTraits<double>::Zero;
82 for (
unsigned int j = 0; j < MapType::ImageDimension; ++j)
83 theDistance += pow(
static_cast<double>(offset[j]), 2.0) / pow(
static_cast<double>(radius[j]), 2.0);
85 if (theDistance <= 1.0)
87 for (
unsigned int j = 0; j < MapType::ImageDimension; ++j)
89 int pos = offset[j] + position[j];
90 positionToUpdate[j] = (pos >= 0) ? pos % mapSize[j] : (mapSize[j] - ((-pos) % mapSize[j])) % mapSize[j];
96 double tempBeta = beta / (1.0 + theDistance);
97 for (
unsigned int j = 0; j < newNeuron.Size(); ++j)
99 if (!DistanceType::IsMissingValue(sample[j]))
100 newNeuron[j] +=
static_cast<typename NeuronType::ValueType
>((sample[j] - tempNeuron[j]) * tempBeta);
102 map->SetPixel(positionToUpdate, newNeuron);
107 template <
class TListSample,
class TMap,
class TSOMLearningBehaviorFunctor,
class TSOMNeighborhoodBehaviorFunctor>
110 Superclass::PrintSelf(os, indent);