Commit 18c3b6c200837c48c92dc4be44614f70c74cac86

Authored by Jordi Inglada
1 parent 18e22f14

ENH: add indices and check duplicates

Showing 1 changed file with 23 additions and 7 deletions   Show diff stats
include/iota2FeatureExtraction.h
... ... @@ -103,9 +103,9 @@ public:
103 103 m_CopyInputBands{pars.CopyInputBands}
104 104 {
105 105 m_NumberOfDates = m_NumberOfInputComponents/m_ComponentsPerDate;
106   - const auto finalNumberOfFeatures = m_NumberOfFeatures-
  106 + auto numberOfOutputFeatures = m_NumberOfFeatures-
107 107 ((m_RelativeReflectances&&m_RemoveDuplicates)?1:0);
108   - m_NumberOfOutputComponents = ( finalNumberOfFeatures +
  108 + m_NumberOfOutputComponents = ( numberOfOutputFeatures +
109 109 (m_CopyInputBands?
110 110 m_ComponentsPerDate:0))*m_NumberOfDates;
111 111 auto max_index_band = std::max({m_RedIndex, m_NIRIndex, m_SWIRIndex});
... ... @@ -191,23 +191,39 @@ protected:
191 191 auto red = *(inIt+m_RedIndex-1);
192 192 auto nir = *(inIt+m_NIRIndex-1);
193 193 auto swir = *(inIt+m_SWIRIndex-1);
194   - auto ndvi = normalized_index(nir, red);
195   - auto ndwi = normalized_index(swir, nir);
196 194 VectorType tmpVec(m_ComponentsPerDate);
197 195 std::transform(inIt, inIt+m_ComponentsPerDate,tmpVec.begin(),
198 196 [](decltype(*inIt)x){ return x*x;});
199 197 auto brightness = std::sqrt(std::accumulate(tmpVec.begin(), tmpVec.end(),
200 198 ValueType{0}));
201 199 //append the features
202   - outVec[copyOffset+date_counter] = ndvi * m_NormalizedIndexFactor;
203   - outVec[copyOffset+m_NumberOfDates+date_counter] = ndwi * m_NormalizedIndexFactor;
204   - outVec[copyOffset+m_NumberOfDates*2+date_counter] = brightness;
  200 + size_t featureOffset{0};
  201 +
  202 + AddNormalizedIndexMaybe(nir, red, m_RedIndex, featureOffset,
  203 + copyOffset, outVec, date_counter);
  204 + AddNormalizedIndexMaybe(swir, nir, m_NIRIndex, featureOffset,
  205 + copyOffset, outVec, date_counter);
  206 + outVec[copyOffset+m_NumberOfDates*featureOffset+date_counter] = brightness;
205 207 }
206 208 //move to the next date
207 209 std::advance(inIt, m_ComponentsPerDate);
208 210 ++date_counter;
209 211 }
210 212 }
  213 +
  214 + void AddNormalizedIndexMaybe(ValueType refl, ValueType refrefl,
  215 + size_t refindex, size_t& featureOffset,
  216 + size_t copyOffset, VectorType& outVec,
  217 + size_t date_counter)
  218 + {
  219 + if(!m_RemoveDuplicates || m_ReferenceIndex != refindex)
  220 + {
  221 + outVec[copyOffset+m_NumberOfDates*featureOffset+date_counter] =
  222 + normalized_index(refl, refrefl) * m_NormalizedIndexFactor;
  223 + ++featureOffset;
  224 + }
  225 + }
  226 +
211 227 size_t m_ComponentsPerDate;
212 228 size_t m_RedIndex;
213 229 size_t m_NIRIndex;
... ...