Commit 18e22f147fd1c30e5b2550bf08e87ca031a01d09

Authored by Jordi Inglada
1 parent 574c1c6f

REFAC: function for feature computation

Showing 1 changed file with 42 additions and 36 deletions   Show diff stats
include/iota2FeatureExtraction.h
... ... @@ -123,13 +123,53 @@ public:
123 123 p.GetDataPointer()+p.GetSize());
124 124 //copy the spectral bands
125 125 auto outVec = VectorType(m_NumberOfOutputComponents);
126   - size_t copyOffset = (m_CopyInputBands?m_NumberOfInputComponents:0);
127 126 //copy the input reflectances
128 127 if(m_CopyInputBands)
129 128 {
130 129 AddReflectances(inVec, outVec);
131 130 }
132 131  
  132 + ComputeFeatures(inVec, outVec);
  133 +
  134 + //convert the result to a pixel
  135 + for(size_t i=0; i<m_NumberOfOutputComponents; i++)
  136 + result[i] = outVec[i];
  137 + return result;
  138 + }
  139 +
  140 + bool operator!=(FeatureExtractionFunctor<PixelType> f)
  141 + {
  142 + return m_ComponentsPerDate != f.m_ComponentsPerDate;
  143 + }
  144 +
  145 + size_t GetNumberOfOutputComponents() const
  146 + {
  147 + return m_NumberOfOutputComponents;
  148 + }
  149 +
  150 +protected:
  151 + void AddReflectances(const VectorType& inVec, VectorType& outVec)
  152 + {
  153 + if(!m_RelativeReflectances)
  154 + {
  155 + std::copy(inVec.cbegin(), inVec.cend(), outVec.begin());
  156 + }
  157 + else
  158 + {
  159 + auto inIt = inVec.cbegin();
  160 + auto outIt = outVec.begin();
  161 + while(inIt != inVec.cend())
  162 + {
  163 + (*outIt) = normalized_index(*inIt, *(inIt+m_ReferenceIndex-1));
  164 + ++inIt;
  165 + ++outIt;
  166 + }
  167 + }
  168 + }
  169 +
  170 + void ComputeFeatures(const VectorType& inVec, VectorType& outVec)
  171 + {
  172 + size_t copyOffset = (m_CopyInputBands?m_NumberOfInputComponents:0);
133 173 size_t date_counter{0};
134 174 auto inIt = inVec.cbegin();
135 175 while(inIt != inVec.cend())
... ... @@ -153,7 +193,7 @@ public:
153 193 auto swir = *(inIt+m_SWIRIndex-1);
154 194 auto ndvi = normalized_index(nir, red);
155 195 auto ndwi = normalized_index(swir, nir);
156   - decltype(inVec) tmpVec(m_ComponentsPerDate);
  196 + VectorType tmpVec(m_ComponentsPerDate);
157 197 std::transform(inIt, inIt+m_ComponentsPerDate,tmpVec.begin(),
158 198 [](decltype(*inIt)x){ return x*x;});
159 199 auto brightness = std::sqrt(std::accumulate(tmpVec.begin(), tmpVec.end(),
... ... @@ -167,40 +207,6 @@ public:
167 207 std::advance(inIt, m_ComponentsPerDate);
168 208 ++date_counter;
169 209 }
170   - //convert the result to a pixel
171   - for(size_t i=0; i<m_NumberOfOutputComponents; i++)
172   - result[i] = outVec[i];
173   - return result;
174   - }
175   -
176   - bool operator!=(FeatureExtractionFunctor<PixelType> f)
177   - {
178   - return m_ComponentsPerDate != f.m_ComponentsPerDate;
179   - }
180   -
181   - size_t GetNumberOfOutputComponents() const
182   - {
183   - return m_NumberOfOutputComponents;
184   - }
185   -
186   -protected:
187   - void AddReflectances(const VectorType& inVec, VectorType& outVec)
188   - {
189   - if(!m_RelativeReflectances)
190   - {
191   - std::copy(inVec.cbegin(), inVec.cend(), outVec.begin());
192   - }
193   - else
194   - {
195   - auto inIt = inVec.cbegin();
196   - auto outIt = outVec.begin();
197   - while(inIt != inVec.cend())
198   - {
199   - (*outIt) = normalized_index(*inIt, *(inIt+m_ReferenceIndex-1));
200   - ++inIt;
201   - ++outIt;
202   - }
203   - }
204 210 }
205 211 size_t m_ComponentsPerDate;
206 212 size_t m_RedIndex;
... ...