Isis 3 Programmer Reference
Equalization.h
1 #ifndef Equalization_h
2 #define Equalization_h
3 
9 /* SPDX-License-Identifier: CC0-1.0 */
10 #include <vector>
11 
12 #include <QString>
13 #include <QStringList>
14 
15 #include "FileList.h"
16 #include "LeastSquares.h"
17 #include "OverlapNormalization.h"
18 
19 using namespace std;
20 
21 namespace Isis {
22  class Buffer;
23  class OverlapStatistics;
24  class Pvl;
25  class PvlGroup;
26  class PvlObject;
27  class Statistics;
122  class Equalization {
123  public:
124  Equalization(OverlapNormalization::SolutionType sType, QString fromListName);
125  virtual ~Equalization();
126 
127  void addHolds(QString holdListName);
128 
129  void calculateStatistics(double samplingPercent,
130  int mincnt,
131  bool wtopt,
132  LeastSquares::SolveMethod methodType);
133  void recalculateStatistics(QString inStatsFileName);
134  void importStatistics(QString instatsFileName);
135  void applyCorrection(QString toListName);
136 
137  PvlGroup getResults();
138  void write(QString outstatsFileName);
139 
140  double evaluate(double dn, int imageIndex, int bandIndex) const;
141 
142  protected:
151  public:
152  ImageAdjustment(OverlapNormalization::SolutionType sType) { m_sType = sType; }
153  ~ImageAdjustment() {}
154 
155  void addGain(double gain) {
156  gains.push_back(gain);
157  }
158 
159  void addOffset(double offset) {
160  offsets.push_back(offset);
161  }
162 
163  void addAverage(double average) {
164  avgs.push_back(average);
165  }
166 
167  double getGain(int index) const {
168  return gains[index];
169  }
170 
171  double getOffset(int index) const {
172  return offsets[index];
173  }
174 
175  double getAverage(int index) const {
176  return avgs[index];
177  }
178 
179  double evaluate(double dn, int index) const {
180  double result = Null;
181 
182  double gain = gains[index];
183  if (m_sType != OverlapNormalization::GainsWithoutNormalization) {
184  double offset = offsets[index];
185  double avg = avgs[index];
186  result = (dn - avg) * gain + offset + avg;
187  }
188  else {
189  result = dn * gain;
190  }
191 
192  return result;
193  }
194 
195  private:
196  vector<double> gains;
197  vector<double> offsets;
198  vector<double> avgs;
199 
201  };
202 
211  public:
219  CalculateFunctor(Statistics *stats, double percent) {
220  m_stats = stats;
221  m_linc = (int) (100.0 / percent + 0.5);
222  }
223 
224  virtual ~CalculateFunctor() {}
225 
226  void operator()(Buffer &in) const;
227 
228  protected:
229  virtual void addStats(Buffer &in) const;
230 
231  private:
233  int m_linc;
234  };
235 
243  class ApplyFunctor {
244  public:
245  ApplyFunctor(const ImageAdjustment *adjustment) {
246  m_adjustment = adjustment;
247  }
248 
249  void operator()(Buffer &in, Buffer &out) const;
250 
251  private:
253  };
254 
255  protected:
256  Equalization();
257  void loadInputs(QString fromListName);
258  void setInput(int index, QString value);
259  const FileList &getInputs() const;
260 
261  // Should these be protected or private? (Recall children, i.e. HiEqual... can't
262  // access Equalization's private vars directly)
263  void calculateBandStatistics();
264  void calculateOverlapStatistics();
265 
266  virtual void fillOutList(FileList &outList, QString toListName);
267  virtual void errorCheck(QString fromListName);
268 
269  void generateOutputs(FileList &outList);
270  void loadOutputs(FileList &outList, QString toListName);
271  void loadHolds(OverlapNormalization *oNorm);
272 
273  void setResults();
274 
275  void clearAdjustments();
276  void addAdjustment(ImageAdjustment *adjustment);
277 
278  void clearNormalizations();
279  void clearOverlapStatistics();
280 
281  void addValid(int count);
282  void addInvalid(int count);
283 
284  void fromPvl(const PvlObject &inStats);
285  void setSolved(bool solved);
286  bool isSolved() const;
287 
288  private:
289  void init();
290  QVector<int> validateInputStatistics(QString instatsFileName);
291 
294  bool m_wtopt;
295 
296  FileList m_imageList; //<! List of input image filenames
297 
303  int m_mincnt;
304 
305  int m_maxCube;
306  int m_maxBand;
307 
309 
310  vector<ImageAdjustment *> m_adjustments; //<! Corrective factors for equalization
311  vector<int> m_holdIndices;
312  vector<bool> m_doesOverlapList;
313  vector<bool> m_alreadyCalculated;
314  vector<OverlapNormalization *> m_overlapNorms;
315  vector<OverlapStatistics *> m_overlapStats;
316 
321 
323  };
324 };
325 
326 #endif
Isis::Statistics
This class is used to accumulate statistics on double arrays.
Definition: Statistics.h:94
Isis::OverlapNormalization::SolutionType
SolutionType
Enumeration for whether user/programmer wants to calculate new gains, offsets, or both when solving.
Definition: OverlapNormalization.h:111
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::Equalization::m_lsqMethod
LeastSquares::SolveMethod m_lsqMethod
Least squares method for solving normalization correcitve factors.
Definition: Equalization.h:320
Isis::Equalization::CalculateFunctor::CalculateFunctor
CalculateFunctor(Statistics *stats, double percent)
Constructs a CalculateFunctor.
Definition: Equalization.h:219
Isis::Equalization::m_holdIndices
vector< int > m_holdIndices
Indices of images being held.
Definition: Equalization.h:311
Isis::Equalization::m_recalculating
bool m_recalculating
Indicates if recalculating with loaded statistics.
Definition: Equalization.h:293
Isis::Equalization::m_maxCube
int m_maxCube
Number of input images.
Definition: Equalization.h:305
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::LeastSquares::SolveMethod
SolveMethod
Definition: LeastSquares.h:112
QStringList
Isis::Equalization::m_results
Pvl * m_results
Calculation results and normalization corrective factors (if solved)
Definition: Equalization.h:322
Isis::Equalization::m_normsSolved
bool m_normsSolved
Indicates if corrective factors were solved.
Definition: Equalization.h:292
Isis::Buffer
Buffer for reading and writing cube data.
Definition: Buffer.h:53
Isis::Equalization::m_wtopt
bool m_wtopt
Whether or not overlaps should be weighted.
Definition: Equalization.h:294
Isis::Equalization::ApplyFunctor
This class is used as a functor to apply adjustments (equalize) to an image.
Definition: Equalization.h:243
Isis::Equalization::m_sType
OverlapNormalization::SolutionType m_sType
The normalization solution type for solving normalizations (offsets, gains, or both)
Definition: Equalization.h:318
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Equalization::m_invalidCnt
int m_invalidCnt
Number of invalid overlaps.
Definition: Equalization.h:302
Isis::OverlapNormalization
Calculate the bases and multipliers for normalizing overlapping "data sets" (e.g.,...
Definition: OverlapNormalization.h:61
Isis::Equalization::ImageAdjustment
Definition: Equalization.h:150
Isis::Equalization::CalculateFunctor::m_linc
int m_linc
Line increment value when calculating statistics.
Definition: Equalization.h:233
Isis::Equalization::m_overlapNorms
vector< OverlapNormalization * > m_overlapNorms
Normalization data for input images.
Definition: Equalization.h:314
Isis::Equalization::CalculateFunctor
This class is used as a functor calculate image statistics.
Definition: Equalization.h:210
Isis::Equalization::m_maxBand
int m_maxBand
Number of bands in each input image.
Definition: Equalization.h:306
Isis::Equalization::m_overlapStats
vector< OverlapStatistics * > m_overlapStats
Calculated overlap statistics.
Definition: Equalization.h:315
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Isis::Equalization
This class can be used to calculate, read in, and/or apply equalization statistics for a list of file...
Definition: Equalization.h:122
Isis::Equalization::m_badFiles
QStringList m_badFiles
List of image names that don't overlap.
Definition: Equalization.h:308
Isis::Equalization::m_mincnt
int m_mincnt
Minimum number of pixels for an overlap to be considered valid.
Definition: Equalization.h:303
std
Namespace for the standard library.
Isis::Equalization::ApplyFunctor::m_adjustment
const ImageAdjustment * m_adjustment
ImageAdjustment to equalize image.
Definition: Equalization.h:252
Isis::Equalization::m_alreadyCalculated
vector< bool > m_alreadyCalculated
Which images that have statistics already calculated.
Definition: Equalization.h:313
Isis::Equalization::m_samplingPercent
double m_samplingPercent
Percentage of the lines to consider when gathering cube and overlap statistics (process-by-line)
Definition: Equalization.h:298
QVector< int >
Isis::FileList
Internalizes a list of files.
Definition: FileList.h:54
Isis::Equalization::m_doesOverlapList
vector< bool > m_doesOverlapList
Which images have a valid overlap.
Definition: Equalization.h:312
Isis::Equalization::m_validCnt
int m_validCnt
Number of valid overlaps.
Definition: Equalization.h:301
Isis::Equalization::CalculateFunctor::m_stats
Statistics * m_stats
Calculated statistics.
Definition: Equalization.h:232
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16