21 HiEqualization::HiEqualization(QString fromListName) :
23 loadInputs(fromListName);
27 HiEqualization::~HiEqualization() {
31 void HiEqualization::calculateStatistics() {
33 const FileList &imageList = getInputs();
34 QString maxCubeStr =
toString((
int) imageList.size());
37 vector<Statistics *> statsList;
38 vector<Statistics *> leftStatsList;
39 vector<Statistics *> rightStatsList;
40 for (
int img = 0; img < imageList.size(); img++) {
41 Statistics *stats =
new Statistics();
42 Statistics *statsLeft =
new Statistics();
43 Statistics *statsRight =
new Statistics();
45 QString cubeStr =
toString((
int) img + 1);
48 p.Progress()->SetText(
"Calculating Statistics for Cube " +
49 cubeStr +
" of " + maxCubeStr);
50 CubeAttributeInput att;
51 QString inp = imageList[img].toString();
52 p.SetInputCube(inp, att);
53 HiCalculateFunctor func(stats, statsLeft, statsRight, 100.0);
54 p.ProcessCubeInPlace(func,
false);
56 statsList.push_back(stats);
57 leftStatsList.push_back(statsLeft);
58 rightStatsList.push_back(statsRight);
62 OverlapNormalization oNorm(statsList);
66 for (
int i = 0; i < imageList.size() - 1; i++) {
68 oNorm.AddOverlap(*rightStatsList[i], i, *leftStatsList[j], j,
69 rightStatsList[i]->ValidPixels());
78 for (
int img = 0; img < imageList.size(); img++) {
80 adjustment->addGain(oNorm.Gain(img));
81 adjustment->addOffset(oNorm.Offset(img));
82 adjustment->addAverage(oNorm.Average(img));
83 addAdjustment(adjustment);
86 addValid(imageList.size() - 1);
91 void HiEqualization::fillOutList(FileList &outList, QString toListName) {
92 if (toListName.isEmpty()) {
93 generateOutputs(outList);
97 loadOutputs(tempList, toListName);
99 for (
unsigned int i = 0; i < movedIndices.size(); i++) {
100 outList.push_back(tempList[movedIndices[i]]);
106 void HiEqualization::errorCheck(QString fromListName) {
107 const FileList &imageList = getInputs();
110 if (imageList.size() > 10) {
111 QString msg =
"The input file [" + fromListName +
112 "] cannot contain more than 10 file names";
117 const int cpmm2ccd[] = {0, 1, 2, 3, 12, 4, 10, 11, 5, 13, 6, 7, 8, 9};
121 for (
int i = 0; i < imageList.size(); i++) {
124 cube1.open(imageList[i].
toString());
125 PvlGroup &from1Instrument = cube1.group(
"INSTRUMENT");
126 int cpmmNumber = from1Instrument[
"CpmmNumber"];
127 ccds.push_back(cpmm2ccd[cpmmNumber]);
131 movedIndices.push_back(i);
133 catch (IException &e) {
134 QString msg =
"The [" + imageList[i].toString() +
135 "] file is not a valid HiRise image";
141 QString msg =
"The [" + imageList[i].toString() +
142 "] file is not a valid HiRise image";
148 for (
int i = 0; i < imageList.size() - 1; i++) {
149 int id1 = getCCDType(ccds[i]);
150 int id2 = getCCDType(ccds[i + 1]);
154 string msg =
"The list of input images must be all RED, all IR, or ";
161 for (
int i = 1; i < imageList.size(); i++) {
162 QString temp = imageList[i].toString();
164 int movedIndex = movedIndices[i];
169 while (j >= 0 && ccd2 > ccd1) {
170 setInput(j + 1, imageList[j].
toString());
171 ccds[j + 1] = ccds[j];
172 movedIndices[j + 1] = movedIndices[j];
175 if (j >= 0) ccd2 = ccds[j];
178 setInput(j + 1, temp);
180 movedIndices[j + 1] = movedIndex;
184 if (ccds[0] == 10 || ccds[0] == 11) {
185 if (imageList.size() != 2) {
186 string msg =
"A list of IR images must have exactly two ";
191 else if (ccds[0] == 12 || ccds[0] == 13) {
192 if (imageList.size() != 2) {
193 string msg =
"A list of BG images must have exactly two ";
202 int HiEqualization::getCCDType(
int ccd) {
204 return (ccd >= 0 && ccd <= 9) ? 0 : (ccd == 10 || ccd == 11) ? 1 : 2;
208 void HiEqualization::HiCalculateFunctor::addStats(Buffer &in)
const {
209 Equalization::CalculateFunctor::addStats(in);
216 unsigned int intersect = (in.size() == 682 || in.size() == 683) ?
217 18 : (48 * in.size()) / 2048;
219 m_statsLeft->
AddData(&in[0], intersect);
220 m_statsRight->
AddData(&in[in.size() - intersect], intersect);