Unverified Commit 0a96d6d0 authored by Kristin Berry's avatar Kristin Berry Committed by GitHub
Browse files

Revert reverted histogram PR and handle conflicts. (#4004)



* Revert reverted histogram PR and handle conflicts

* Added changelog entry

* ERROR

* local stats fix

* Added new ImageHistogram class

* Actually added the ImageHistogram class

* Made shared variable protected so subclass can access it

* Used virtual functions and reverted Cube::histogram to return a Historgram

* Added back pipe to dev/null in makefile

* Fixes to some app and unit test in the hist PR

* More test fixes

* Final updates to programs and test data for new histogram calculations

* Split the rolls of imagehistogram and histogram

* Added and updated unit test truth data

* Added the ImageHistogram unittest file

* Resolved last comments on hist PR

Co-authored-by: default avatarAdam Paquette <acpaquette@usgs.gov>
parent 644fea3f
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -38,8 +38,11 @@ update the Unreleased link so that it compares against the latest release tag.

 - Equalizer now reports the correct equation and values used to perform the adjustment. [#3987](https://github.com/USGS-Astrogeology/ISIS3/issues/3987)
 - Map2cam now works correctly when specifying bands for input cubes. [#3856](https://github.com/USGS-Astrogeology/ISIS3/issues/3856)
 
 - mro/hideal2pds app now writes the correct SAMPLE_BIT_MASK values to the output label. [#3978](https://github.com/USGS-Astrogeology/ISIS3/issues/3978)

  - For Histograms in ISIS, updated the math for calculating what bin data should be placed in and the min/max values of each bin to be more intuitive. In addition, the output of hist and cnethist were changed to display the min/max values of each bin instead of the middle pixel's DN. [#3882](https://github.com/USGS-Astrogeology/ISIS3/issues/3882)

 ### Added

 - A Gui Helper gear was added to hist to fill in the minimum and maximum parameters with what would have been automatically calculated. [#3880](https://github.com/USGS-Astrogeology/ISIS3/issues/3880)
+11 −6
Original line number Diff line number Diff line
@@ -17,16 +17,22 @@ void IsisMain() {
  double gsigma = Isis::Application::GetUserInterface().GetDouble("GSIGMA");

  for(int i = 0; i < icube->bandCount(); i++) {
    Histogram hist = *(icube->histogram(i + 1));
    double mean = (hist.Maximum() + hist.Minimum()) / 2.0;
    double stdev = (hist.Maximum() - hist.Minimum()) / (2.0 * gsigma);
    stretch.push_back(new GaussianStretch(hist, mean, stdev));
    Histogram *hist = icube->histogram(i + 1);
    double mean = (hist->Maximum() + hist->Minimum()) / 2.0;
    double stdev = (hist->Maximum() - hist->Minimum()) / (2.0 * gsigma);
    stretch.push_back(new GaussianStretch(*hist, mean, stdev));
  }

  p.StartProcess(gauss);
  for(int i = 0; i < icube->bandCount(); i++) delete stretch[i];
  stretch.clear();
  p.EndProcess();

  while(!stretch.empty()) {
      delete stretch.back();
      stretch.pop_back();
  }

  stretch.clear();
}

// Processing routine for the pca with one input cube
@@ -36,4 +42,3 @@ void gauss(Buffer &in, Buffer &out) {
    out[i] = stretch[in.Band(i)-1]->Map(in[i]);
  }
}
+6 −0
Original line number Diff line number Diff line
@@ -84,6 +84,12 @@
      Updated logic such that min/max values are no longer calculated from .cub
      if values are provided by the user.  Fixes #3881.
    </change>
    <change name="Kaitlyn Lee" date="2020-06-11">
      Added "Pixels Below Min" and "Pixels Above Max" to the CSV output and changed how the data is
      outputted. Originally, the CSV output and the GUI histogram would use the DN value in the
      middle of a bin to represent that bin. That is, the CSV output used to have a "DN" value that
      was the bin's middle pixel DN. This was not intuitive to users. Removed the "DN" value and added "MinInclusive" and "MaxExclusive" to the CSV so that bins are represented by their min/max values. These changes were also reflected in the histrogram creation. The x-axis is now based off of the min value of a bin instead of the middle value. These changes were made alongside changes made to Histogram and cnethist.
    </change>
    <change name="Kristin Berry" date="2020-06-25">
      Re-added the ability to set number of bins without setting min/max values after the last update. 
      Follow-on to #3881.
+51 −51
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

#include "CubePlotCurve.h"
#include "Histogram.h"
#include "ImageHistogram.h"
#include "HistogramItem.h"
#include "HistogramPlotWindow.h"
#include "LineManager.h"
@@ -66,10 +67,12 @@ void IsisMain() {
    hist = new Histogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins);
  }
  else {
    hist = new Histogram(*icube, 1, p.Progress());

    if (ui.WasEntered("NBINS")){
      hist->SetBins(ui.GetInteger("NBINS"));
      hist = new ImageHistogram(*icube, 1, p.Progress(), 1, 1, Null, Null, ui.GetInteger("NBINS"));
    }
    else {
      hist = new ImageHistogram(*icube, 1, p.Progress());
    }
  }

@@ -107,6 +110,8 @@ void IsisMain() {
    fout << endl;
    fout << "Total Pixels:      " << hist->TotalPixels() << endl;
    fout << "Valid Pixels:      " << hist->ValidPixels() << endl;
    fout << "Pixels Below Min:  " << hist->UnderRangePixels() << endl;
    fout << "Pixels Above Max:  " << hist->OverRangePixels() << endl;
    fout << "Null Pixels:       " << hist->NullPixels() << endl;
    fout << "Lis Pixels:        " << hist->LisPixels() << endl;
    fout << "Lrs Pixels:        " << hist->LrsPixels() << endl;
@@ -116,10 +121,12 @@ void IsisMain() {
    //  Write histogram in tabular format
    fout << endl;
    fout << endl;
    fout << "DN,Pixels,CumulativePixels,Percent,CumulativePercent" << endl;
    fout << "MinInclusive,MaxExclusive,Pixels,CumulativePixels,Percent,CumulativePercent" << endl;

    Isis::BigInt total = 0;
    double cumpct = 0.0;
    double low;
    double high;

    for (int i = 0; i < hist->Bins(); i++) {
      if (hist->BinCount(i) > 0) {
@@ -127,7 +134,10 @@ void IsisMain() {
        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.;
        cumpct += pct;

        fout << hist->BinMiddle(i) << ",";
        hist->BinRange(i, low, high);

        fout << low << ",";
        fout << high << ",";
        fout << hist->BinCount(i) << ",";
        fout << total << ",";
        fout << pct << ",";
@@ -174,13 +184,16 @@ void IsisMain() {
    QVector<QPointF> binCountData;
    QVector<QPointF> cumPctData;
    double cumpct = 0.0;
    double low;
    double high;
    for (int i = 0; i < hist->Bins(); i++) {
      if (hist->BinCount(i) > 0) {
        binCountData.append(QPointF(hist->BinMiddle(i), hist->BinCount(i) ) );
        hist->BinRange(i, low, high);
        binCountData.append(QPointF(low, hist->BinCount(i) ) );

        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.;
        double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.0;
        cumpct += pct;
        cumPctData.append(QPointF(hist->BinMiddle(i), cumpct) );
        cumPctData.append(QPointF(low, cumpct) );
      }
    }

@@ -199,21 +212,13 @@ void IsisMain() {
    cdfCurve->setYAxis(QwtPlot::yLeft);
    cdfCurve->setPen(*pen);

    //These are all variables needed in the following for loop.
    //----------------------------------------------
    QVector<QwtIntervalSample> intervals(binCountData.size() );
//     double maxYValue = DBL_MIN;
//     double minYValue = DBL_MAX;
//     // ---------------------------------------------
//
    for (int y = 0; y < binCountData.size(); y++) {

      intervals[y].interval = QwtInterval(binCountData[y].x(),
                                          binCountData[y].x() + hist->BinSize());

      intervals[y].value = binCountData[y].y();
//       if(values[y] > maxYValue) maxYValue = values[y];
//       if(values[y] < minYValue) minYValue = values[y];
    }

    QPen percentagePen(Qt::red);
@@ -226,10 +231,6 @@ void IsisMain() {

    plot->add(histCurve);
    plot->add(cdfCurve);
//     plot->fillTable();

//     plot->setScale(QwtPlot::yLeft, 0, maxYValue);
//     plot->setScale(QwtPlot::xBottom, hist.Minimum(), hist.Maximum());

    QLabel *label = new QLabel("  Average = " + QString::number(hist->Average()) + '\n' +
           "\n  Minimum = " + QString::number(hist->Minimum()) + '\n' +
@@ -283,4 +284,3 @@ void helperButtonCalcMinMax() {
  ui.PutDouble("MAXIMUM", cubeStats.Maximum());

}
+5 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ histTruth.txt.IGNORELINES = Cube
histTruthNbins.txt.IGNORELINES = Cube
TEMP = $(OUTPUT)/histTruth.txt
TEMPNBINS = $(OUTPUT)/histTruthNbins.txt
TEMPMINMAX = $(OUTPUT)/histTruthMinMax.txt

include $(ISISROOT)/make/isismake.tsts

@@ -18,3 +19,7 @@ commands:
	# Test with setting nbins
	$(APPNAME) from=$(INPUT)/isisTruth.cub nbins=25\
	  to=$(TEMPNBINS) > /dev/null;

	# Test with a min and max
	$(APPNAME) from=$(INPUT)/isisTruth.cub\
          to=$(TEMPMINMAX) minimum=0 maximum=255 nbins=255> /dev/null;
Loading