//! Compute automatic stretch for a portion of the cube void ChipViewport::computeStretch(Stretch &stretch, bool force) { if (p_stretchLocked && !force) { stretch = *p_stretch; } else { Statistics stats; for (int line = 1; line < p_chip->Lines(); line++) { for (int samp = 1; samp < p_chip->Samples(); samp++) { double value = p_chip->GetValue(samp, line); stats.AddData(&value, 1); } } Histogram hist(stats.BestMinimum(), stats.BestMaximum()); for (int line = 1; line <= p_chip->Lines(); line++) { for (int samp = 1; samp <= p_chip->Samples(); samp++) { double value = p_chip->GetValue(samp, line); hist.AddData(&value, 1); } } stretch.ClearPairs(); if (hist.Percent(0.5) != hist.Percent(99.5)) { stretch.AddPair(hist.Percent(0.5), 0.0); stretch.AddPair(hist.Percent(99.5), 255.0); } else { stretch.AddPair(-DBL_MAX, 0.0); stretch.AddPair(DBL_MAX, 255.0); } *p_stretch = stretch; } }
void IsisMain() { // Setup the input and output cubes ProcessByLine p; // used for getting histograms from input cubes Cube *icube = p.SetInputCube("FROM", Isis::OneBand); p.SetOutputCube ("TO"); // Histogram parameters UserInterface &ui = Application::GetUserInterface(); double minimum = ui.GetDouble("MINPER"); double maximum = ui.GetDouble("MAXPER"); int increment = ui.GetInteger("INCREMENT"); // Histograms from input cubes Histogram *from = icube->Histogram(); Histogram *match = icube->Histogram(); double fromMin = from->Percent(minimum); double fromMax = from->Percent(maximum); int fromBins = from->Bins(); double data[fromBins]; double slope = (fromMax - fromMin) / (fromBins - 1); // Set "match" to have the same data range and number of bins as "to" match->SetBins(fromBins); match->SetValidRange(fromMin, fromMax); for (int i = 0; i < fromBins; i++) { data[i] = fromMin + (slope * i); } match->AddData(data, fromBins); stretch.ClearPairs(); double lastPer = from->Percent(minimum); stretch.AddPair(lastPer, match->Percent(minimum)); for (double i = increment+minimum; i < maximum; i += increment) { double curPer = from->Percent(i); if (lastPer < curPer) { if(abs(lastPer - curPer) > DBL_EPSILON) { stretch.AddPair(curPer, match->Percent(i)); lastPer = curPer; } } } double curPer = from->Percent(maximum); if (lastPer < curPer && abs(lastPer - curPer) > DBL_EPSILON) { stretch.AddPair(curPer, match->Percent(maximum)); } // Start the processing p.StartProcess(remap); p.EndProcess(); }
void IsisMain() { // Setup the input and output cubes along with histograms ProcessByLine p; Cube *mcube = p.SetInputCube("MATCH", Isis::OneBand); Histogram *match = mcube->histogram(); p.ClearInputCubes(); Cube *icube = p.SetInputCube("FROM", Isis::OneBand); Histogram *from = icube->histogram(); p.SetOutputCube("TO"); // Histogram specifications UserInterface &ui = Application::GetUserInterface(); double minimum = ui.GetDouble("MINPER"); double maximum = ui.GetDouble("MAXPER"); stretch.ClearPairs(); // CDF mode selected if(ui.GetString("STRETCH") == "CDF") { int increment = ui.GetInteger("INCREMENT"); double lastPer = from->Percent(minimum); stretch.AddPair(lastPer, match->Percent(minimum)); for(double i = increment + minimum; i < maximum; i += increment) { double curPer = from->Percent(i); if(lastPer < curPer && abs(lastPer - curPer) > DBL_EPSILON) { stretch.AddPair(curPer, match->Percent(i)); lastPer = curPer; } } double curPer = from->Percent(maximum); if(lastPer < curPer && abs(lastPer - curPer) > DBL_EPSILON) { stretch.AddPair(curPer, match->Percent(maximum)); } } // Modal mode is selected else { stretch.AddPair(from->Percent(minimum), match->Percent(minimum)); stretch.AddPair(from->Mode(), match->Mode()); stretch.AddPair(from->Percent(maximum), match->Percent(maximum)); } // Start the processing p.StartProcess(remap); p.EndProcess(); }
void IsisMain () { stretch.ClearPairs(); for (int i=0; i<6; i++) { gapCount[i] = 0; suspectGapCount[i] = 0; invalidCount[i] = 0; lisCount[i] = 0; hisCount[i] = 0; validCount[i] = 0; } void TranslateHiriseEdrLabels (Filename &labelFile, Cube *); void SaveHiriseCalibrationData (ProcessImportPds &process, Cube *, Pvl &pdsLabel); void SaveHiriseAncillaryData (ProcessImportPds &process, Cube *); void FixDns8 (Buffer &buf); void FixDns16 (Buffer &buf); ProcessImportPds p; Pvl pdsLabel; UserInterface &ui = Application::GetUserInterface(); // Get the input filename and make sure it is a HiRISE EDR Filename inFile = ui.GetFilename("FROM"); iString id; bool projected; try { Pvl lab(inFile.Expanded()); id = (string) lab.FindKeyword ("DATA_SET_ID"); projected = lab.HasObject("IMAGE_MAP_PROJECTION"); } catch (iException &e) { string msg = "Unable to read [DATA_SET_ID] from input file [" + inFile.Expanded() + "]"; throw iException::Message(iException::Io,msg, _FILEINFO_); } //Checks if in file is rdr if( projected ) { string msg = "[" + inFile.Name() + "] appears to be an rdr file."; msg += " Use pds2isis."; throw iException::Message(iException::User,msg, _FILEINFO_); } id.ConvertWhiteSpace(); id.Compress(); id.Trim(" "); if (id != "MRO-M-HIRISE-2-EDR-V1.0") { string msg = "Input file [" + inFile.Expanded() + "] does not appear to be " + "in HiRISE EDR format. DATA_SET_ID is [" + id + "]"; throw iException::Message(iException::Io,msg, _FILEINFO_); } p.SetPdsFile (inFile.Expanded(), "", pdsLabel); // Make sure the data we need for the BLOBs is saved by the Process p.SaveFileHeader(); p.SaveDataPrefix(); p.SaveDataSuffix(); // Let the Process create the output file but override any commandline // output bit type and min/max. It has to be 16bit for the rest of hi2isis // to run. // Setting the min/max to the 16 bit min/max keeps all the dns (including // the 8 bit special pixels from changing their value when they are mapped // to the 16 bit output. CubeAttributeOutput &outAtt = ui.GetOutputAttribute("TO"); outAtt.PixelType (Isis::SignedWord); outAtt.Minimum((double)VALID_MIN2); outAtt.Maximum((double)VALID_MAX2); Cube *ocube = p.SetOutputCube(ui.GetFilename("TO"), outAtt); p.StartProcess (); TranslateHiriseEdrLabels (inFile, ocube); // Pull out the lookup table so we can apply it in the second pass // and remove it from the labels. // Add the UNLUTTED keyword to the instrument group so we know // if the lut has been used to convert back to 14 bit data PvlGroup &instgrp = ocube->GetGroup("Instrument"); PvlKeyword lutKey = instgrp["LookupTable"]; PvlSequence lutSeq; lutSeq = lutKey; // Set up the Stretch object with the info from the lookup table // If the first entry is (0,0) then no lut was applied. if ((lutKey.IsNull()) || (lutSeq.Size()==1 && lutSeq[0][0]=="0" && lutSeq[0][1]=="0")) { stretch.AddPair(0.0, 0.0); stretch.AddPair(65536.0, 65536.0); instgrp.AddKeyword(PvlKeyword("Unlutted","TRUE")); instgrp.DeleteKeyword ("LookupTable"); } // The user wants it unlutted else if (ui.GetBoolean("UNLUT")) { for (int i=0; i<lutSeq.Size(); i++) { stretch.AddPair(i, (((double)lutSeq[i][0] + (double)lutSeq[i][1]) / 2.0)); } instgrp.AddKeyword(PvlKeyword("Unlutted","TRUE")); instgrp.DeleteKeyword ("LookupTable"); } // The user does not want the data unlutted else { stretch.AddPair(0.0, 0.0); stretch.AddPair(65536.0, 65536.0); instgrp.AddKeyword(PvlKeyword("Unlutted","FALSE")); } ocube->PutGroup(instgrp); // Save the calibration and ancillary data as BLOBs. Both get run thru the // lookup table just like the image data. SaveHiriseCalibrationData (p, ocube, pdsLabel); SaveHiriseAncillaryData (p, ocube); // Save off the input bit type so we know how to process it on the // second pass below. Isis::PixelType inType = p.PixelType(); // All finished with the ImportPds object p.EndProcess (); // Make another pass thru the data using the output file in read/write mode // This allows us to correct gaps, remap special pixels and accumulate some // counts lsbGap = ui.GetBoolean("LSBGAP"); ProcessByLine p2; string ioFile = ui.GetFilename("TO"); CubeAttributeInput att; p2.SetInputCube(ioFile, att, ReadWrite); p2.Progress()->SetText("Converting special pixels"); section = 4; p2.StartProcess((inType == Isis::UnsignedByte) ? FixDns8 : FixDns16); p2.EndProcess(); // Log the results of the image conversion PvlGroup results("Results"); results += PvlKeyword ("From", inFile.Expanded()); results += PvlKeyword ("CalibrationBufferGaps", gapCount[0]); results += PvlKeyword ("CalibrationBufferLIS", lisCount[0]); results += PvlKeyword ("CalibrationBufferHIS", hisCount[0]); results += PvlKeyword ("CalibrationBufferPossibleGaps", suspectGapCount[0]); results += PvlKeyword ("CalibrationBufferInvalid", invalidCount[0]); results += PvlKeyword ("CalibrationBufferValid", validCount[0]); results += PvlKeyword ("CalibrationImageGaps", gapCount[1]); results += PvlKeyword ("CalibrationImageLIS", lisCount[1]); results += PvlKeyword ("CalibrationImageHIS", hisCount[1]); results += PvlKeyword ("CalibrationImagePossibleGaps", suspectGapCount[1]); results += PvlKeyword ("CalibrationImageInvalid", invalidCount[1]); results += PvlKeyword ("CalibrationImageValid", validCount[1]); results += PvlKeyword ("CalibrationDarkGaps", gapCount[2]); results += PvlKeyword ("CalibrationDarkLIS", lisCount[2]); results += PvlKeyword ("CalibrationDarkHIS", hisCount[2]); results += PvlKeyword ("CalibrationDarkPossibleGaps", suspectGapCount[2]); results += PvlKeyword ("CalibrationDarkInvalid", invalidCount[2]); results += PvlKeyword ("CalibrationDarkValid", validCount[2]); results += PvlKeyword ("ObservationBufferGaps", gapCount[3]); results += PvlKeyword ("ObservationBufferLIS", lisCount[3]); results += PvlKeyword ("ObservationBufferHIS", hisCount[3]); results += PvlKeyword ("ObservationBufferPossibleGaps", suspectGapCount[3]); results += PvlKeyword ("ObservationBufferInvalid", invalidCount[3]); results += PvlKeyword ("ObservationBufferValid", validCount[3]); results += PvlKeyword ("ObservationImageGaps", gapCount[4]); results += PvlKeyword ("ObservationImageLIS", lisCount[4]); results += PvlKeyword ("ObservationImageHIS", hisCount[4]); results += PvlKeyword ("ObservationImagePossibleGaps", suspectGapCount[4]); results += PvlKeyword ("ObservationImageInvalid", invalidCount[4]); results += PvlKeyword ("ObservationImageValid", validCount[4]); results += PvlKeyword ("ObservationDarkGaps", gapCount[5]); results += PvlKeyword ("ObservationDarkLIS", lisCount[5]); results += PvlKeyword ("ObservationDarkHIS", hisCount[5]); results += PvlKeyword ("ObservationDarkPossibleGaps", suspectGapCount[5]); results += PvlKeyword ("ObservationDarkInvalid", invalidCount[5]); results += PvlKeyword ("ObservationDarkValid", validCount[5]); // Write the results to the log Application::Log(results); return; }
void IsisMain() { colorOffset = 0; frameletLines.clear(); outputCubes.clear(); uveven = NULL; uvodd = NULL; viseven = NULL; visodd = NULL; ProcessImportPds p; Pvl pdsLab; UserInterface &ui = Application::GetUserInterface(); QString fromFile = ui.GetFileName("FROM"); flip = false;//ui.GetBoolean("FLIP"); p.SetPdsFile(fromFile, "", pdsLab); ValidateInputLabels(pdsLab); inputCubeLines = p.Lines(); lookupTable = Stretch(); // read the lut if the option is on if(ui.GetBoolean("UNLUT") && pdsLab["LRO:LOOKUP_TABLE_TYPE"][0] == "STORED") { PvlKeyword lutKeyword = pdsLab["LRO:LOOKUP_CONVERSION_TABLE"]; for(int i = 0; i < lutKeyword.size(); i ++) { IString lutPair = lutKeyword[i]; lutPair.ConvertWhiteSpace(); lutPair.Remove("() "); QString outValueMin = lutPair.Token(" ,").ToQt(); QString outValueMax = lutPair.Token(" ,").ToQt(); lookupTable.AddPair(i, (toDouble(outValueMin) + toDouble(outValueMax)) / 2.0); } } QString instModeId = pdsLab["INSTRUMENT_MODE_ID"]; // this will be used to convert num input lines to num output lines, // only changed for when both uv and vis exist (varying summing) double visOutputLineRatio = 1.0; double uvOutputLineRatio = 1.0; int numFilters = 0; if(ui.GetBoolean("COLOROFFSET")) { colorOffset = ui.GetInteger("COLOROFFSETSIZE"); } // Determine our band information based on // INSTRUMENT_MODE_ID - FILTER_NUMBER is // only going to be used for BW images if(instModeId == "COLOR") { numFilters = 7; frameletLines.push_back(4); frameletLines.push_back(4); frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); uveven = new Cube(); uvodd = new Cube(); viseven = new Cube(); visodd = new Cube(); // 14 output lines (1 framelet) from 5vis/2uv lines visOutputLineRatio = 14.0 / (14.0 * 5.0 + 4.0 * 2.0); // 4 output lines (1 framelet) from 5vis/2uv lines uvOutputLineRatio = 4.0 / (14.0 * 5.0 + 4.0 * 2.0); } else if(instModeId == "VIS") { numFilters = 5; frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); frameletLines.push_back(14); viseven = new Cube(); visodd = new Cube(); // 14 output lines (1 framelet) from 5vis/2uv lines visOutputLineRatio = 14.0 / (14.0 * 5.0); } else if(instModeId == "UV") { numFilters = 2; frameletLines.push_back(4); frameletLines.push_back(4); uveven = new Cube(); uvodd = new Cube(); // 4 output lines (1 framelet) from 2uv lines uvOutputLineRatio = 4.0 / (4.0 * 2.0); } else if(instModeId == "BW") { numFilters = 1; frameletLines.push_back(14); viseven = new Cube(); visodd = new Cube(); } padding.resize(numFilters); for(int filter = 0; filter < numFilters; filter++) { padding[filter] = (colorOffset * frameletLines[filter]) * filter; // dont count UV for VIS offsetting if(instModeId == "COLOR" && filter > 1) { padding[filter] -= 2 * colorOffset * frameletLines[filter]; } } FileName baseFileName(ui.GetFileName("TO")); if(uveven && uvodd) { // padding[1] is max padding for UV int numSamples = ((viseven) ? p.Samples() / 4 : p.Samples()); numSamples = 128; // UV is alway sum 4 so it is 128 samples int numLines = (int)(uvOutputLineRatio * inputCubeLines + 0.5) + padding[1]; int numBands = 2; uveven->setDimensions(numSamples, numLines, numBands); uveven->setPixelType(Isis::Real); QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.even.cub"; uveven->create(filename); uvodd->setDimensions(numSamples, numLines, numBands); uvodd->setPixelType(Isis::Real); filename = baseFileName.path() + "/" + baseFileName.baseName() + ".uv.odd.cub"; uvodd->create(filename); } if(viseven && visodd) { // padding[size-1] is max padding for vis (padding[0] or padding[4] or padding[6]) int numSamples = p.Samples(); int numLines = (int)(visOutputLineRatio * inputCubeLines + 0.5) + padding[padding.size()-1]; int numBands = ((uveven) ? padding.size() - 2 : padding.size()); viseven->setDimensions(numSamples, numLines, numBands); viseven->setPixelType(Isis::Real); QString filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.even.cub"; viseven->create(filename); visodd->setDimensions(numSamples, numLines, numBands); visodd->setPixelType(Isis::Real); filename = baseFileName.path() + "/" + baseFileName.baseName() + ".vis.odd.cub"; visodd->create(filename); } Pvl isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab; TranslateLabels(pdsLab, isis3VisEvenLab, isis3VisOddLab, isis3UvEvenLab, isis3UvOddLab); writeNullsToFile(); p.StartProcess(separateFramelets); p.EndProcess(); // Add original labels OriginalLabel origLabel(pdsLab); int numFramelets = padding.size(); PvlKeyword numFrameletsKeyword("NumFramelets", toString(numFramelets)); if(uveven) { for(int grp = 0; grp < isis3UvEvenLab.groups(); grp++) { uveven->putGroup(isis3UvEvenLab.group(grp)); } History history("IsisCube"); history.AddEntry(); uveven->write(history); uveven->write(origLabel); uveven->close(); delete uveven; uveven = NULL; } if(uvodd) { for(int grp = 0; grp < isis3UvOddLab.groups(); grp++) { uvodd->putGroup(isis3UvOddLab.group(grp)); } History history("IsisCube"); history.AddEntry(); uvodd->write(history); uvodd->write(origLabel); uvodd->close(); delete uvodd; uvodd = NULL; } if(viseven) { for(int grp = 0; grp < isis3VisEvenLab.groups(); grp++) { viseven->putGroup(isis3VisEvenLab.group(grp)); } History history("IsisCube"); history.AddEntry(); viseven->write(history); viseven->write(origLabel); viseven->close(); delete viseven; viseven = NULL; } if(visodd) { for(int grp = 0; grp < isis3VisOddLab.groups(); grp++) { visodd->putGroup(isis3VisOddLab.group(grp)); } History history("IsisCube"); history.AddEntry(); visodd->write(history); visodd->write(origLabel); visodd->close(); delete visodd; visodd = NULL; } }