OTB  9.0.0
Orfeo Toolbox
otbSOMWithMissingValue.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbSOMWithMissingValue_hxx
23 #define otbSOMWithMissingValue_hxx
24 
25 #include "otbSOMWithMissingValue.h"
26 
27 #include "itkNumericTraits.h"
28 #include "itkNeighborhoodIterator.h"
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 template <class TListSample, class TMap, class TSOMLearningBehaviorFunctor, class TSOMNeighborhoodBehaviorFunctor>
35 {
36 }
37 
38 template <class TListSample, class TMap, class TSOMLearningBehaviorFunctor, class TSOMNeighborhoodBehaviorFunctor>
40 {
41 }
42 
50 template <class TListSample, class TMap, class TSOMLearningBehaviorFunctor, class TSOMNeighborhoodBehaviorFunctor>
52  SizeType& radius)
53 {
54  // output map pointer
55  MapPointerType map = this->GetOutput(0);
56 
57  // winner index in the map
58  IndexType position = map->GetWinner(sample);
59  NeuronType winner = map->GetPixel(position);
60 
61  // Local neighborhood definition
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);
66 
67  // Here, the periodic update is achieved 'by hand' since
68  // PeriodicBoundaryCondition does not allow modifying
69  // VectorImage contents
70  SizeType mapSize = mapRegion.GetSize();
71  IndexType positionToUpdate;
72 
73  // Iterate over the neighborhood of the winner neuron
74  it.SetLocation(position);
75 
76  for (unsigned int i = 0; i < it.Size(); ++i)
77  {
78  typename NeighborhoodIteratorType::OffsetType offset = it.GetOffset(i);
79 
80  // The neighborhood is of elliptic shape
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);
84 
85  if (theDistance <= 1.0)
86  {
87  for (unsigned int j = 0; j < MapType::ImageDimension; ++j)
88  {
89  int pos = offset[j] + position[j];
90  positionToUpdate[j] = (pos >= 0) ? pos % mapSize[j] : (mapSize[j] - ((-pos) % mapSize[j])) % mapSize[j];
91  }
92 
93  NeuronType tempNeuron = it.GetPixel(i);
94  NeuronType newNeuron(tempNeuron);
95 
96  double tempBeta = beta / (1.0 + theDistance);
97  for (unsigned int j = 0; j < newNeuron.Size(); ++j)
98  {
99  if (!DistanceType::IsMissingValue(sample[j]))
100  newNeuron[j] += static_cast<typename NeuronType::ValueType>((sample[j] - tempNeuron[j]) * tempBeta);
101  }
102  map->SetPixel(positionToUpdate, newNeuron);
103  }
104  }
105 }
106 
107 template <class TListSample, class TMap, class TSOMLearningBehaviorFunctor, class TSOMNeighborhoodBehaviorFunctor>
109 {
110  Superclass::PrintSelf(os, indent);
111 
112 } // end PrintSelf
113 
114 } // end iof namespace otb
115 
116 #endif
otb::SOMWithMissingValue::SOMWithMissingValue
SOMWithMissingValue()
Definition: otbSOMWithMissingValue.hxx:34
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SOMWithMissingValue::SizeType
MapType::SizeType SizeType
Definition: otbSOMWithMissingValue.h:66
otbMacro.h
otb::SOMWithMissingValue::MapPointerType
MapType::Pointer MapPointerType
Definition: otbSOMWithMissingValue.h:68
otb::SOMWithMissingValue::NeuronType
MapType::PixelType NeuronType
Definition: otbSOMWithMissingValue.h:63
otbSOMWithMissingValue.h
otb::SOMWithMissingValue::~SOMWithMissingValue
~SOMWithMissingValue() override
Definition: otbSOMWithMissingValue.hxx:39
otb::SOMWithMissingValue::UpdateMap
void UpdateMap(const NeuronType &sample, double beta, SizeType &radius) override
Definition: otbSOMWithMissingValue.hxx:51
otb::SOMWithMissingValue::IndexType
MapType::IndexType IndexType
Definition: otbSOMWithMissingValue.h:65
otb::SOMWithMissingValue::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbSOMWithMissingValue.hxx:108