Commit 87a2820e authored by Makayla Shepherd's avatar Makayla Shepherd
Browse files

Stretch parameters added to hideal2pds. References #1761.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6425 41f8697f-d340-4b68-9986-7bafba869bb8
parent c4a9f437
Loading
Loading
Loading
Loading
+49 −1
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@
using namespace Isis;
using namespace std;

double *g_min, *g_max;

pair<double, double> inputRange(Cube *inputCube);
void updatePdsLabelTimeParametersGroup(Pvl &pdsLabel);
void updatePdsLabelImageObject(PvlObject *isisCubeLab, Pvl &pdsLabel);
@@ -38,6 +40,7 @@ void IsisMain() {
  // Get user interface and create a ProcessExportPds object
  UserInterface &ui = Application::GetUserInterface();  
  ProcessExportPds p;
  Process pHist;
  Cube *inputCube = p.SetInputCube("FROM");
  PvlObject *isisCubeLab = inputCube->label();

@@ -65,10 +68,52 @@ void IsisMain() {
    throw IException(IException::Io, msg, _FILEINFO_);
  }
  
  g_min = new double[inputCube->bandCount()];
  g_max = new double[inputCube->bandCount()];

  for (int band = 1; band <= inputCube->bandCount(); ++band) {

    if (ui.GetString("TYPE").compare("AUTOMATIC") == 0) {
      // Set up a histogram for this band. This call sets the input range
      // by making an initial stats pass to find the data min and max
      Histogram hist(*inputCube, band, pHist.Progress());

      // Loop and accumulate histogram
      pHist.Progress()->SetText("Gathering Histogram");
      pHist.Progress()->SetMaximumSteps(inputCube->lineCount());
      pHist.Progress()->CheckStatus();
      LineManager line(*inputCube);
      for (int i = 1; i <= inputCube->lineCount(); i++) {
        line.SetLine(i, band);
        inputCube->read(line);
        hist.AddData(line.DoubleBuffer(), line.size());
        pHist.Progress()->CheckStatus();
      }

      // get the requested cumulative percentages
      g_min[band-1] = ui.GetDouble("MINPER") == 0.0 ? hist.Minimum() : hist.Percent(ui.GetDouble("MINPER"));
      g_max[band-1] = ui.GetDouble("MAXPER") == 100.0 ? hist.Maximum() : hist.Percent(ui.GetDouble("MAXPER"));
    }
    else {
      g_min[band-1] = ui.GetDouble("MIN");
      g_max[band-1] = ui.GetDouble("MAX");
    }
  }

  // Find the minimum min and maximum max for all bands
  double minmin = g_min[0];
  double maxmax = g_max[0];
  for (int band = 1; band < inputCube->bandCount(); ++band) {
    if (g_min[band] < minmin) minmin = g_min[band];
    if (g_max[band] > maxmax) maxmax = g_max[band];
  }

  pHist.EndProcess();

  // use histogram to calculate min/max for input range
  pair<double, double> inRange;
  inRange = inputRange(inputCube);
  p.SetInputRange(inRange.first, inRange.second);
  p.SetInputRange(minmin, maxmax);
  // output bit type will be 16bit unsigned word
  p.SetOutputType(Isis::UnsignedWord); 
  p.SetOutputNull(Isis::NULLU2);         
@@ -227,6 +272,9 @@ void IsisMain() {
  p.StartProcess(outputStream);
  p.EndProcess();
  outputStream.close();
  
  delete [] g_min;
  delete [] g_max;
}

/**
+98 −0
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@
    <change name="Jeannie Backer" date="2012-11-21">
      Original Version of hideal2pds. Fixes #678.
    </change>
    <change name="Makayla Shepherd" date="2015-10-06">
      Added stretch parameters. Fixes #1761.
    </change>
  </history>

  <groups>
@@ -120,7 +123,102 @@
          error.
        </description>
      </parameter>
    </group>
    <group name="Stretch">
          <parameter name="TYPE">
        <type>string</type>
        <default><item>AUTOMATIC</item></default>
        <brief>
          Select the type of stretch
        </brief>
        <description>
          This parameter is used to select one of two ways to stretch output
          pixels.  The are AUTOMATIC or MANUAL.
        </description>
        <list>
          <option value="AUTOMATIC">
            <brief>Automatically calculate stretch</brief>
            <description>Automatically calculate stretch</description>
            <exclusions>
              <item>MIN</item> 
              <item>MAX</item>
            </exclusions>
          </option>
          <option value="MANUAL">
            <brief>User defined stretch</brief>
            <description>User defined stretch</description>
              <exclusions>
              <item>MINPER</item> 
              <item>MAXPER</item>
            </exclusions>
          </option>
        </list>
      </parameter>
          <parameter name="MIN">
              <type>double</type>
              <brief>
                  Lower bound of the stretch
              </brief>
              <description>
                  Lower bound for the manually specified stretch.
              </description>
          </parameter>
          <parameter name="MAX">
              <type>double</type>
              <brief>
                  Upper bound of the stretch
              </brief>
              <description>
                  Upper bound for the manually specified stretch.
              </description>
          </parameter>
          <parameter name="MINPER">
          <type>double</type>
          <default>
            <item>0.0</item>
          </default>
          <brief>
            Minimum DN valid percentage
          </brief>
          <description>
            The cumulative percentage value to be mapped to the minimum 
            valid pixel for the specified number of bits. For example: With BITS=10
            and MINPER=1.0, the DN which corresponds to the cummulative
            percent of 1.0 will be mapped to 3, where 0 represents NULL, 1
            represents LRS and 2 represents LIS.
          </description>
          <minimum inclusive="yes">0.0</minimum>
          <maximum inclusive="yes">100.0</maximum>
          <lessThanOrEqual>
              <item>
                  MAXPER
                </item>
          </lessThanOrEqual>
        </parameter>

        <parameter name="MAXPER">
          <type>double</type>
          <default>
            <item>100.0</item>
          </default>
          <brief>
            Mazimum DN valid percentage
          </brief>
          <description>
            The cumulative percentage value to be mapped to the maximum 
            valid pixel for the specified number of bits. For example: With BITS=10
            and MINPER=99.0, the DN which corresponds to the cummulative
            percent of 99.0 will be mapped to 1021, 1021=(2**bits)-1-2. 
            Where 1023 represents HIS and 1022 represents HRS.
          </description>
          <minimum inclusive="yes">0.0</minimum>
          <maximum inclusive="yes">100.0</maximum>
          <greaterThanOrEqual>
              <item>
                MINPER
              </item>
          </greaterThanOrEqual>
        </parameter>
      </group>
  </groups>
</application>
+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ commands:
	$(APPNAME) FROM=$(INPUT)/input.cub \
	  to=$(OUTPUT)/output.img \
	  rationale_desc="user entered" \
	  version="2.0" > /dev/null;
	  version="2.0" type=automatic \
	  minper=.5 maxper=99.5 > /dev/null;
	pds2hideal from=$(OUTPUT)/output.lbl \
	  to=$(OUTPUT)/hideal2pds2hideal.cub > /dev/null;
	tabledump from=$(OUTPUT)/hideal2pds2hideal.cub \