9#include "HiEqualization.h"
15#include "IException.h"
16#include "LineManager.h"
17#include "OverlapNormalization.h"
18#include "OverlapStatistics.h"
20#include "ProcessByLine.h"
29 HiEqualization::HiEqualization(QString fromListName) :
31 loadInputs(fromListName);
35 HiEqualization::~HiEqualization() {
39 void HiEqualization::calculateStatistics() {
41 const FileList &imageList = getInputs();
42 QString maxCubeStr =
toString((
int) imageList.size());
45 vector<Statistics *> statsList;
46 vector<Statistics *> leftStatsList;
47 vector<Statistics *> rightStatsList;
48 for (
int img = 0; img < imageList.size(); img++) {
49 Statistics *stats =
new Statistics();
50 Statistics *statsLeft =
new Statistics();
51 Statistics *statsRight =
new Statistics();
53 QString cubeStr =
toString((
int) img + 1);
56 p.Progress()->SetText(
"Calculating Statistics for Cube " +
57 cubeStr +
" of " + maxCubeStr);
58 CubeAttributeInput att;
59 QString inp = imageList[img].toString();
60 p.SetInputCube(inp, att);
61 HiCalculateFunctor func(stats, statsLeft, statsRight, 100.0);
62 p.ProcessCubeInPlace(func,
false);
64 statsList.push_back(stats);
65 leftStatsList.push_back(statsLeft);
66 rightStatsList.push_back(statsRight);
70 OverlapNormalization oNorm(statsList);
74 for (
int i = 0; i < imageList.size() - 1; i++) {
76 oNorm.AddOverlap(*rightStatsList[i], i, *leftStatsList[j], j,
77 rightStatsList[i]->ValidPixels());
83 oNorm.Solve(OverlapNormalization::Both);
87 for (
int img = 0; img < imageList.size(); img++) {
88 ImageAdjustment *adjustment =
new ImageAdjustment(OverlapNormalization::Both);
89 adjustment->addGain(oNorm.Gain(img));
90 adjustment->addOffset(oNorm.Offset(img));
91 adjustment->addAverage(oNorm.Average(img));
92 addAdjustment(adjustment);
95 addValid(imageList.size() - 1);
100 void HiEqualization::fillOutList(FileList &outList, QString toListName) {
101 if (toListName.isEmpty()) {
102 generateOutputs(outList);
106 loadOutputs(tempList, toListName);
108 for (
unsigned int i = 0; i < movedIndices.size(); i++) {
109 outList.push_back(tempList[movedIndices[i]]);
115 void HiEqualization::errorCheck(QString fromListName) {
116 const FileList &imageList = getInputs();
119 if (imageList.size() > 10) {
120 QString msg =
"The input file [" + fromListName +
121 "] cannot contain more than 10 file names";
122 throw IException(IException::User, msg, _FILEINFO_);
126 const int cpmm2ccd[] = {0, 1, 2, 3, 12, 4, 10, 11, 5, 13, 6, 7, 8, 9};
130 for (
int i = 0; i < imageList.size(); i++) {
134 PvlGroup &from1Instrument = cube1.group(
"INSTRUMENT");
135 int cpmmNumber = from1Instrument[
"CpmmNumber"];
136 ccds.push_back(cpmm2ccd[cpmmNumber]);
140 movedIndices.push_back(i);
143 QString msg =
"The [" + imageList[i].toString() +
144 "] file is not a valid HiRise image";
145 throw IException(e, IException::User, msg, _FILEINFO_);
150 QString msg =
"The [" + imageList[i].toString() +
151 "] file is not a valid HiRise image";
152 throw IException(IException::User, msg, _FILEINFO_);
157 for (
int i = 0; i < imageList.size() - 1; i++) {
158 int id1 = getCCDType(ccds[i]);
159 int id2 = getCCDType(ccds[i + 1]);
163 string msg =
"The list of input images must be all RED, all IR, or ";
165 throw IException(IException::User, msg, _FILEINFO_);
170 for (
int i = 1; i < imageList.size(); i++) {
171 QString temp = imageList[i].toString();
173 int movedIndex = movedIndices[i];
178 while (j >= 0 && ccd2 > ccd1) {
179 setInput(j + 1, imageList[j].
toString());
180 ccds[j + 1] = ccds[j];
181 movedIndices[j + 1] = movedIndices[j];
184 if (j >= 0) ccd2 = ccds[j];
187 setInput(j + 1, temp);
189 movedIndices[j + 1] = movedIndex;
193 if (ccds[0] == 10 || ccds[0] == 11) {
194 if (imageList.size() != 2) {
195 string msg =
"A list of IR images must have exactly two ";
197 throw IException(IException::User, msg, _FILEINFO_);
200 else if (ccds[0] == 12 || ccds[0] == 13) {
201 if (imageList.size() != 2) {
202 string msg =
"A list of BG images must have exactly two ";
204 throw IException(IException::User, msg, _FILEINFO_);
211 int HiEqualization::getCCDType(
int ccd) {
213 return (ccd >= 0 && ccd <= 9) ? 0 : (ccd == 10 || ccd == 11) ? 1 : 2;
217 void HiEqualization::HiCalculateFunctor::addStats(Buffer &in)
const {
218 Equalization::CalculateFunctor::addStats(in);
225 unsigned int intersect = (in.size() == 682 || in.size() == 683) ?
226 18 : (48 * in.size()) / 2048;
228 m_statsLeft->AddData(&in[0], intersect);
229 m_statsRight->AddData(&in[in.size() - intersect], intersect);
IO Handler for Isis Cubes.
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
Internalizes a list of files.
Contains multiple PvlContainers.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.