7#include "OverlapNormalization.h"
11#include "BasisFunction.h"
12#include "IException.h"
13#include "LeastSquares.h"
14#include "Statistics.h"
37 statsList.size(), statsList.size());
40 statsList.size(), statsList.size());
43 m_gains.resize(statsList.size());
45 for (
unsigned int i = 0; i < statsList.size(); i++) {
91 const Statistics &area1,
const unsigned index1,
92 const Statistics &area2,
const unsigned index2,
95 string msg =
"The index 1 is outside the bounds of the list.";
99 string msg =
"The index 2 is outside the bounds of the list.";
110 string msg =
"All weights must be positive real numbers.";
124 if (avg1 == 0 || avg2 == 0)
return NoContrast;
151 string msg =
"None of the input images overlap";
159 string msg =
"Unable to normalize overlaps. The number of overlaps and "
160 "holds must be greater than the number of input images";
174 const std::vector<double> alphaWeight(sparseMatrixCols, 1/1000.0);
176 m_gainLsq->SetParameterWeights( alphaWeight );
182 for (
int overlap = 0; overlap < (int)
m_overlapList.size(); overlap++) {
184 int id1 = curOverlap.
index1;
185 int id2 = curOverlap.index2;
187 vector<double> input;
189 for (
int i = 0; i < (int)input.size(); i++) input[i] = 0.0;
200 vector<double> input;
202 for (
int i = 0; i < (int)input.size(); i++) input[i] = 0.0;
219 for (
int overlap = 0; overlap < (int)
m_overlapList.size(); overlap++) {
221 int id1 = curOverlap.
index1;
222 int id2 = curOverlap.index2;
224 vector<double> input;
226 for (
int i = 0; i < (int)input.size(); i++) input[i] = 0.0;
233 if (curOverlap.area1.StandardDeviation() == 0.0) {
237 tanp = curOverlap.area2.StandardDeviation()
238 / curOverlap.area1.StandardDeviation();
242 if (curOverlap.area1.Average() == 0.0) {
246 tanp = curOverlap.area2.Average() / curOverlap.area1.Average();
262 vector<double> input;
264 for (
int i = 0; i < (int)input.size(); i++) input[i] = 0.0;
295 string msg =
"The index was out of bounds for the list of statistics.";
316 string msg =
"The index was out of bounds for the list of statistics.";
337 string msg =
"The index was out of bounds for the list of statistics.";
360 string msg =
"The least squares equation has not been successfully ";
361 msg +=
"solved yet.";
Generic linear equation class.
int Coefficients() const
Returns the number of coefficients for the equation.
double Coefficient(int i) const
Returns the ith coefficient.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
@ Programmer
This error is for when a programmer made an API call that was illegal.
Generic least square fitting class.
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
Store statistics pertaining to the overlapping areas and indices (corresponding to the statistics lis...
int index1
Index corresponding to m_statsList for the first overlapping data set.
Statistics area1
Overlapping area for the first data set.
std::vector< double > m_gains
Vector of calculated gains filled by the Solve method.
std::vector< int > m_idHoldList
Vector of indices corresponding to the m_statsList vector representing data sets to be held in soluti...
OverlapNormalization(std::vector< Statistics * > statsList)
Constructs an OverlapNormalization object.
std::vector< double > m_weights
Vector of weights for every valid overlap.
bool m_solved
Whether or not the least squares solution has been solved.
BasisFunction * m_offsetFunction
The offset function to be solved.
double Offset(const unsigned index) const
Returns the calculated offset (base) for the given data set.
std::vector< double > m_deltas
Vector of delta values (differences between the averages of two overlapping data sets) for every vali...
LeastSquares * m_offsetLsq
The least squares object that calculates offsets.
BasisFunction * m_gainFunction
The gain function to be solved.
std::vector< Overlap > m_overlapList
Vector of valid overlaps collected.
double Average(const unsigned index) const
Returns the calculated average DN value for the given data set.
std::vector< double > m_offsets
Vector of calculated offsets filled by the Solve method.
virtual ~OverlapNormalization()
Destroys the OverlapNormalization object, frees up pointers.
AddStatus AddOverlap(const Statistics &area1, const unsigned index1, const Statistics &area2, const unsigned index2, double weight=1.0)
Attempts to add the given overlap data to a collection of valid overlaps, and returns the success or ...
SolutionType
Enumeration for whether user/programmer wants to calculate new gains, offsets, or both when solving.
@ Offsets
Calculate only the offsets.
@ Gains
Calculate only the gains.
@ GainsWithoutNormalization
The equation being solved for Gains, Offsets, and Both is output = (input - average) * gain + offset ...
AddStatus
The result of the attempt to add overlap data to the list of valid overlaps, where Success is a succe...
@ NoOverlap
Data sets do not overlap one another.
@ Success
Overlap is valid and was added successfully.
@ NoContrast
One or both areas contain no valid average.
std::vector< Statistics * > m_statsList
Vector of Statistics objects for each data set.
double Evaluate(double dn, unsigned index) const
Returns a new DN from an old using the calculated gains and offsets of the data set the pixel belongs...
LeastSquares * m_gainLsq
The least squares object that solves for the new gains.
double Gain(const unsigned index) const
Returns the calculated gain (multiplier) for the given data set.
void Solve(SolutionType type=Both, LeastSquares::SolveMethod method=LeastSquares::QRD)
Attempts to solve the least squares equation for all data sets.
This class is used to accumulate statistics on double arrays.
double Average() const
Computes and returns the average.
BigInt ValidPixels() const
Returns the total number of valid pixels processed.
This is free and unencumbered software released into the public domain.
bool IsSpecial(const double d)
Returns if the input pixel is special.
Namespace for the standard library.