Commit c5a3d51391e9336dc89cb5114b665b3ba4aeb622

Authored by Jordi Inglada
1 parent d6be7f35
Exists in nomalised_features

BUG: correct number of output features

Showing 1 changed file with 23 additions and 15 deletions   Show diff stats
include/iota2FeatureExtraction.h
... ... @@ -103,10 +103,8 @@ public:
103 103 m_CopyInputBands{pars.CopyInputBands}
104 104 {
105 105 m_NumberOfDates = m_NumberOfInputComponents/m_ComponentsPerDate;
106   - if(m_SWIRIndex==0) --m_NumberOfFeatures;
107   - const auto numberOfOutputFeatures = m_NumberOfFeatures-
108   - ((m_RelativeReflectances&&m_RemoveDuplicates)?1:0);
109   - m_NumberOfOutputComponents = ( numberOfOutputFeatures +
  106 + UpdateNumberOfFeatures();
  107 + m_NumberOfOutputComponents = ( m_NumberOfFeatures +
110 108 (m_CopyInputBands?
111 109 m_ComponentsPerDate:0))*m_NumberOfDates;
112 110 const auto max_index_band = std::max({m_RedIndex, m_NIRIndex, m_SWIRIndex});
... ... @@ -149,6 +147,14 @@ public:
149 147 }
150 148  
151 149 protected:
  150 + inline void UpdateNumberOfFeatures()
  151 + {
  152 + if(m_SWIRIndex==0) --m_NumberOfFeatures;
  153 + if((m_RelativeReflectances && m_RemoveDuplicates &&
  154 + (m_ReferenceIndex==m_RedIndex || m_ReferenceIndex==m_NIRIndex)))
  155 + --m_NumberOfFeatures;
  156 + }
  157 +
152 158 inline
153 159 void AddReflectances(const VectorType& inVec, VectorType& outVec)
154 160 {
... ... @@ -210,7 +216,7 @@ protected:
210 216 //compute the features
211 217 const auto red = *(inIt+m_RedIndex-1);
212 218 const auto nir = *(inIt+m_NIRIndex-1);
213   - const auto swir = *(inIt+m_SWIRIndex-1);
  219 + const auto swir = *(inIt+(m_SWIRIndex>0?m_SWIRIndex:1)-1);
214 220 VectorType tmpVec(m_ComponentsPerDate);
215 221 std::transform(inIt, inIt+m_ComponentsPerDate,tmpVec.begin(),
216 222 [](decltype(*inIt)x){ return x*x;});
... ... @@ -219,13 +225,13 @@ protected:
219 225 //append the features
220 226 size_t featureOffset{0};
221 227 //ndvi
222   - AddNormalizedIndexMaybe(nir, red, m_RedIndex, featureOffset,
223   - copyOffset, outVec, date_counter);
  228 + featureOffset = AddNormalizedIndexMaybe(nir, red, m_RedIndex, featureOffset,
  229 + copyOffset, outVec, date_counter);
224 230 //ndwi
225 231 if(m_SWIRIndex!=0)
226 232 {
227   - AddNormalizedIndexMaybe(swir, nir, m_NIRIndex, featureOffset,
228   - copyOffset, outVec, date_counter);
  233 + featureOffset = AddNormalizedIndexMaybe(swir, nir, m_NIRIndex, featureOffset,
  234 + copyOffset, outVec, date_counter);
229 235 }
230 236 outVec[copyOffset+m_NumberOfDates*featureOffset+date_counter] = brightness;
231 237 }
... ... @@ -236,17 +242,19 @@ protected:
236 242 }
237 243  
238 244 inline
239   - void AddNormalizedIndexMaybe(ValueType refl, ValueType refrefl,
240   - size_t refindex, size_t& featureOffset,
241   - size_t copyOffset, VectorType& outVec,
242   - size_t date_counter)
  245 + size_t AddNormalizedIndexMaybe(ValueType refl, ValueType refrefl,
  246 + size_t refindex, size_t featureOffset,
  247 + size_t copyOffset, VectorType& outVec,
  248 + size_t date_counter)
243 249 {
244   - if(!m_RemoveDuplicates || m_ReferenceIndex != refindex)
  250 + auto result = featureOffset;
  251 + if(!(m_RemoveDuplicates && m_ReferenceIndex == refindex))
245 252 {
246 253 outVec[copyOffset+m_NumberOfDates*featureOffset+date_counter] =
247 254 normalized_index(refl, refrefl) * m_NormalizedIndexFactor;
248   - ++featureOffset;
  255 + ++result;
249 256 }
  257 + return result;
250 258 }
251 259  
252 260 size_t m_ComponentsPerDate;
... ...