int main(int argc, char *argv[]) { Preference::Preferences(true); cout << setprecision(9); try { FileName fromList("FromList.lst"); QString holdList = "HoldList.lst"; cout << "UnitTest for Equalization" << endl; HiEqualization equalizer(fromList.toString()); equalizer.addHolds(holdList); equalizer.calculateStatistics(); // Open input cube FileList imageList(fromList); for (int i = 0; i < imageList.size(); i++) { ProcessByLine p; CubeAttributeInput att; QString inp = imageList[i].toString(); Cube *inputCube = p.SetInputCube(inp, att); TestFunctor func(&equalizer, inputCube->lineCount(), i); p.ProcessCubeInPlace(func, false); p.EndProcess(); } } catch (IException &e) { e.print(); } }
void IsisMain() { // Create a process by line object ProcessByLine p; // Get the value to put in the cube UserInterface &ui = Application::GetUserInterface(); QString pixels = ui.GetString("PIXELS"); double value = Null; if(pixels == "NULL") { value = NULL8; } else if(pixels == "LIS") { value = LOW_INSTR_SAT8; } else if(pixels == "LRS") { value = LOW_REPR_SAT8; } else if(pixels == "HIS") { value = HIGH_INSTR_SAT8; } else if(pixels == "HRS") { value = HIGH_REPR_SAT8; } else { value = ui.GetDouble("VALUE"); } // Need to pick good min/maxs to ensure the user's value // doesn't get saturated CubeAttributeOutput &att = ui.GetOutputAttribute("TO"); if(IsValidPixel(value)) { if(value == 0.0) { att.setMinimum(value); att.setMaximum(value + 1.0); } if(value < 0.0) { att.setMinimum(value); att.setMaximum(-value); } else { att.setMinimum(-value); att.setMaximum(value); } } else { att.setMinimum(0.0); att.setMaximum(1.0); } // Get the size of the cube and create the cube int samps = ui.GetInteger("SAMPLES"); int lines = ui.GetInteger("LINES"); int bands = ui.GetInteger("BANDS"); p.SetOutputCube(ui.GetFileName("TO"), att, samps, lines, bands); // Make the cube p.ProcessCubeInPlace(ConstantValueFunctor(value), false); p.EndProcess(); }
void HiEqualization::calculateStatistics() { // TODO member variable const FileList &imageList = getInputs(); QString maxCubeStr = toString((int) imageList.size()); // Adds statistics for whole and side regions of every cube vector<Statistics *> statsList; vector<Statistics *> leftStatsList; vector<Statistics *> rightStatsList; for (int img = 0; img < imageList.size(); img++) { Statistics *stats = new Statistics(); Statistics *statsLeft = new Statistics(); Statistics *statsRight = new Statistics(); QString cubeStr = toString((int) img + 1); ProcessByLine p; p.Progress()->SetText("Calculating Statistics for Cube " + cubeStr + " of " + maxCubeStr); CubeAttributeInput att; QString inp = imageList[img].toString(); p.SetInputCube(inp, att); HiCalculateFunctor func(stats, statsLeft, statsRight, 100.0); p.ProcessCubeInPlace(func, false); statsList.push_back(stats); leftStatsList.push_back(statsLeft); rightStatsList.push_back(statsRight); } // Initialize the object that will calculate the gains and offsets OverlapNormalization oNorm(statsList); // Add the known overlaps between two cubes, and apply a weight to each // overlap equal the number of pixels in the overlapping area for (int i = 0; i < imageList.size() - 1; i++) { int j = i + 1; oNorm.AddOverlap(*rightStatsList[i], i, *leftStatsList[j], j, rightStatsList[i]->ValidPixels()); } loadHolds(&oNorm); // Attempt to solve the least squares equation oNorm.Solve(OverlapNormalization::Both); clearAdjustments(); for (int img = 0; img < imageList.size(); img++) { ImageAdjustment *adjustment = new ImageAdjustment(OverlapNormalization::Both); adjustment->addGain(oNorm.Gain(img)); adjustment->addOffset(oNorm.Offset(img)); adjustment->addAverage(oNorm.Average(img)); addAdjustment(adjustment); } addValid(imageList.size() - 1); setResults(); }
void IsisMain() { try { // We will be processing by line ProcessByLine p; double sscale, lscale; int ins, inl, inb; int ons, onl; vector<QString> bands; Cube inCube; // To propogate labels, set input cube, // this cube will be cleared after output cube is set. p.SetInputCube("FROM"); // Setup the input and output cubes UserInterface &ui = Application::GetUserInterface(); QString replaceMode = ui.GetAsString("VPER_REPLACE"); CubeAttributeInput cai(ui.GetAsString("FROM")); bands = cai.bands(); inCube.setVirtualBands(bands); QString from = ui.GetFileName("FROM"); inCube.open(from); ins = inCube.sampleCount(); inl = inCube.lineCount(); inb = inCube.bandCount(); QString alg = ui.GetString("ALGORITHM"); double vper = ui.GetDouble("VALIDPER") / 100.; if(ui.GetString("MODE") == "TOTAL") { ons = ui.GetInteger("ONS"); onl = ui.GetInteger("ONL"); sscale = (double)ins / (double)ons; lscale = (double)inl / (double)onl; } else { sscale = ui.GetDouble("SSCALE"); lscale = ui.GetDouble("LSCALE"); ons = (int)((double)ins / sscale + 0.5); onl = (int)((double)inl / lscale + 0.5); } if(ons > ins || onl > inl) { QString msg = "Number of output samples/lines must be less than or equal"; msg = msg + " to the input samples/lines."; throw IException(IException::User, msg, _FILEINFO_); } // Allocate output file Cube *ocube = p.SetOutputCube("TO", ons, onl, inb); // Our processing routine only needs 1 // the original set was for info about the cube only p.ClearInputCubes(); // Start the processing PvlGroup results; if(alg == "AVERAGE"){ Average average(&inCube, sscale, lscale, vper, replaceMode); p.ProcessCubeInPlace(average, false); results = average.UpdateOutputLabel(ocube); } else if(alg == "NEAREST") { Nearest near(&inCube, sscale, lscale); p.ProcessCubeInPlace(near, false); results = near.UpdateOutputLabel(ocube); } // Cleanup inCube.close(); p.EndProcess(); // Write the results to the log Application::Log(results); } // REFORMAT THESE ERRORS INTO ISIS TYPES AND RETHROW catch (IException &) { throw; } catch (std::exception const &se) { QString message = "std::exception: " + (QString)se.what(); throw IException(IException::User, message, _FILEINFO_); } catch (...) { QString message = "Other Error"; throw IException(IException::User, message, _FILEINFO_); } }