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
19using namespace std;
20
21namespace Isis {
22 class Buffer;
23 class OverlapStatistics;
24 class Pvl;
25 class PvlGroup;
26 class PvlObject;
27 class Statistics;
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
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; }
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];
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
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)
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();
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
304
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
Buffer for reading and writing cube data.
Definition Buffer.h:53
This class is used as a functor to apply adjustments (equalize) to an image.
const ImageAdjustment * m_adjustment
ImageAdjustment to equalize image.
This class is used as a functor calculate image statistics.
Statistics * m_stats
Calculated statistics.
int m_linc
Line increment value when calculating statistics.
CalculateFunctor(Statistics *stats, double percent)
Constructs a CalculateFunctor.
This class can be used to calculate, read in, and/or apply equalization statistics for a list of file...
void calculateBandStatistics()
Calculates the image statistics on a band-by-band basis.
void importStatistics(QString instatsFileName)
Imports statistics for applying correction.
void generateOutputs(FileList &outList)
Generates the names of the equalized cubes if no output list is provided.
void clearAdjustments()
Frees image adjustments.
void loadOutputs(FileList &outList, QString toListName)
Checks that the output image list is correct.
bool m_wtopt
Whether or not overlaps should be weighted.
virtual void errorCheck(QString fromListName)
Checks that the input images have the same mapping groups and same number of bands.
vector< OverlapNormalization * > m_overlapNorms
Normalization data for input images.
void calculateStatistics(double samplingPercent, int mincnt, bool wtopt, LeastSquares::SolveMethod methodType)
Calculates the image and overlap statistics, and then determines corrective factors if possible.
LeastSquares::SolveMethod m_lsqMethod
Least squares method for solving normalization correcitve factors.
PvlGroup getResults()
Returns general information about the equalization.
void addAdjustment(ImageAdjustment *adjustment)
Adds an image adjustment.
void fromPvl(const PvlObject &inStats)
Loads a previous Equalization state from an input pvl object.
void applyCorrection(QString toListName)
Equalizes the input images.
void setSolved(bool solved)
Sets solved state indicating if OverlapNormalizations (corrective factors) were solved.
void clearNormalizations()
Frees overlap normalizations.
int m_maxBand
Number of bands in each input image.
bool m_normsSolved
Indicates if corrective factors were solved.
void clearOverlapStatistics()
Frees overlap statistics.
void recalculateStatistics(QString inStatsFileName)
Recalculates statistics for any new input images.
vector< int > m_holdIndices
Indices of images being held.
void addInvalid(int count)
Increments the number of invalid overlaps by a given amount.
OverlapNormalization::SolutionType m_sType
The normalization solution type for solving normalizations (offsets, gains, or both)
void init()
Initializes member variables to default values.
int m_mincnt
Minimum number of pixels for an overlap to be considered valid.
int m_invalidCnt
Number of invalid overlaps.
bool m_recalculating
Indicates if recalculating with loaded statistics.
void write(QString outstatsFileName)
Write the equalization information (results) to a file.
void addHolds(QString holdListName)
Adds a list of images to be held in the equalization.
void loadInputs(QString fromListName)
Loads in the input images.
double m_samplingPercent
Percentage of the lines to consider when gathering cube and overlap statistics (process-by-line)
Equalization()
Default constructor.
void addValid(int count)
Increments the number of valid overlaps by a given amount.
Pvl * m_results
Calculation results and normalization corrective factors (if solved)
vector< bool > m_doesOverlapList
Which images have a valid overlap.
bool isSolved() const
Indicates if the corrective factors were solved.
int m_maxCube
Number of input images.
void calculateOverlapStatistics()
Calculates the overlap statistics for each pair of input images.
vector< OverlapStatistics * > m_overlapStats
Calculated overlap statistics.
QStringList m_badFiles
List of image names that don't overlap.
void setResults()
Creates the results pvl containing statistics and corrective factors.
vector< bool > m_alreadyCalculated
Which images that have statistics already calculated.
virtual ~Equalization()
Destructor.
QVector< int > validateInputStatistics(QString instatsFileName)
Validates the input statistics pvl file.
int m_validCnt
Number of valid overlaps.
Internalizes a list of files.
Definition FileList.h:54
Calculate the bases and multipliers for normalizing overlapping "data sets" (e.g.,...
SolutionType
Enumeration for whether user/programmer wants to calculate new gains, offsets, or both when solving.
@ GainsWithoutNormalization
The equation being solved for Gains, Offsets, and Both is output = (input - average) * gain + offset ...
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
This class is used to accumulate statistics on double arrays.
Definition Statistics.h:94
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double Null
Value for an Isis Null pixel.
Namespace for the standard library.