From 428f92775d3ae84e4189d38bd419705e44533c7d Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 8 Sep 2020 11:29:29 -0700 Subject: [PATCH 01/16] Revert reverted histogram PR and handle conflicts --- isis/src/base/apps/hist/hist.xml | 6 ++ isis/src/base/apps/hist/main.cpp | 94 ++++++++++----------- isis/src/base/objs/Histogram/Histogram.cpp | 34 +++----- isis/src/base/objs/Histogram/Histogram.h | 5 ++ isis/src/control/apps/cnethist/cnethist.xml | 5 ++ isis/src/control/apps/cnethist/main.cpp | 42 +++++---- 6 files changed, 97 insertions(+), 89 deletions(-) diff --git a/isis/src/base/apps/hist/hist.xml b/isis/src/base/apps/hist/hist.xml index 17c580d68d..09a97d06dd 100644 --- a/isis/src/base/apps/hist/hist.xml +++ b/isis/src/base/apps/hist/hist.xml @@ -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. + + 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. + Re-added the ability to set number of bins without setting min/max values after the last update. Follow-on to #3881. diff --git a/isis/src/base/apps/hist/main.cpp b/isis/src/base/apps/hist/main.cpp index f9a3821ab7..b6e03e6265 100644 --- a/isis/src/base/apps/hist/main.cpp +++ b/isis/src/base/apps/hist/main.cpp @@ -23,7 +23,7 @@ void IsisMain() { Cube *icube = p.SetInputCube("FROM"); UserInterface &ui = Application::GetUserInterface(); - if(!ui.WasEntered("TO") && !ui.IsInteractive()) { + if (!ui.WasEntered("TO") && !ui.IsInteractive()) { QString msg = "The [TO] parameter must be entered"; throw IException(IException::User, msg, _FILEINFO_); } @@ -71,53 +71,60 @@ void IsisMain() { p.Progress()->CheckStatus(); LineManager line(*icube); - for(int i = 1; i <= icube->lineCount(); i++) { + for (int i = 1; i <= icube->lineCount(); i++) { line.SetLine(i); icube->read(line); hist->AddData(line.DoubleBuffer(), line.size()); p.Progress()->CheckStatus(); } - if(!ui.IsInteractive() || ui.WasEntered("TO") ) { + if (!ui.IsInteractive() || ui.WasEntered("TO") ) { // Write the results QString outfile = ui.GetFileName("TO"); ofstream fout; fout.open(outfile.toLatin1().data()); - fout << "Cube: " << ui.GetFileName("FROM") << endl; - fout << "Band: " << icube->bandCount() << endl; - fout << "Average: " << hist->Average() << endl; - fout << "Std Deviation: " << hist->StandardDeviation() << endl; - fout << "Variance: " << hist->Variance() << endl; - fout << "Median: " << hist->Median() << endl; - fout << "Mode: " << hist->Mode() << endl; - fout << "Skew: " << hist->Skew() << endl; - fout << "Minimum: " << hist->Minimum() << endl; - fout << "Maximum: " << hist->Maximum() << endl; + fout << "Cube: " << ui.GetFileName("FROM") << endl; + fout << "Band: " << icube->bandCount() << endl; + fout << "Average: " << hist->Average() << endl; + fout << "Std Deviation: " << hist->StandardDeviation() << endl; + fout << "Variance: " << hist->Variance() << endl; + fout << "Median: " << hist->Median() << endl; + fout << "Mode: " << hist->Mode() << endl; + fout << "Skew: " << hist->Skew() << endl; + fout << "Minimum: " << hist->Minimum() << endl; + fout << "Maximum: " << hist->Maximum() << endl; fout << endl; - fout << "Total Pixels: " << hist->TotalPixels() << endl; - fout << "Valid Pixels: " << hist->ValidPixels() << endl; - fout << "Null Pixels: " << hist->NullPixels() << endl; - fout << "Lis Pixels: " << hist->LisPixels() << endl; - fout << "Lrs Pixels: " << hist->LrsPixels() << endl; - fout << "His Pixels: " << hist->HisPixels() << endl; - fout << "Hrs Pixels: " << hist->HrsPixels() << 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; + fout << "His Pixels: " << hist->HisPixels() << endl; + fout << "Hrs Pixels: " << hist->HrsPixels() << endl; // 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) { + for (int i = 0; i < hist->Bins(); i++) { + if (hist->BinCount(i) > 0) { total += hist->BinCount(i); 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 << ","; @@ -127,10 +134,10 @@ void IsisMain() { fout.close(); } // If we are in gui mode, create a histogram plot - if(ui.IsInteractive()) { + if (ui.IsInteractive()) { // Set the title for the dialog QString title; - if(ui.WasEntered("TITLE") ) { + if (ui.WasEntered("TITLE") ) { title = ui.GetString("TITLE"); } else { @@ -143,19 +150,19 @@ void IsisMain() { ui.TheGui()); // Set the xaxis title if they entered one - if(ui.WasEntered("XAXIS") ) { + if (ui.WasEntered("XAXIS") ) { QString xaxis(ui.GetString("XAXIS")); plot->setAxisLabel(QwtPlot::xBottom, xaxis.toLatin1().data()); } // Set the yLeft axis title if they entered one - if(ui.WasEntered("FREQAXIS") ) { + if (ui.WasEntered("FREQAXIS") ) { QString yaxis(ui.GetString("FREQAXIS")); plot->setAxisLabel(QwtPlot::yRight, yaxis.toLatin1().data()); } // Set the yRight axis title if they entered one - if(ui.WasEntered("PERCENTAXIS") ) { + if (ui.WasEntered("PERCENTAXIS") ) { QString y2axis(ui.GetString("PERCENTAXIS") ); plot->setAxisLabel(QwtPlot::yLeft, y2axis.toLatin1().data()); } @@ -164,13 +171,16 @@ void IsisMain() { QVector binCountData; QVector cumPctData; double cumpct = 0.0; - for(int i = 0; i < hist->Bins(); i++) { - if(hist->BinCount(i) > 0) { - binCountData.append(QPointF(hist->BinMiddle(i), hist->BinCount(i) ) ); - - double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.; + double low; + double high; + for (int i = 0; i < hist->Bins(); i++) { + if (hist->BinCount(i) > 0) { + hist->BinRange(i, low, high); + binCountData.append(QPointF(low, hist->BinCount(i) ) ); + + double pct = (double)hist->BinCount(i) / hist->ValidPixels() * 100.0; cumpct += pct; - cumPctData.append(QPointF(hist->BinMiddle(i), cumpct) ); + cumPctData.append(QPointF(low, cumpct) ); } } @@ -189,21 +199,13 @@ void IsisMain() { cdfCurve->setYAxis(QwtPlot::yLeft); cdfCurve->setPen(*pen); - //These are all variables needed in the following for loop. - //---------------------------------------------- QVector intervals(binCountData.size() ); -// double maxYValue = DBL_MIN; -// double minYValue = DBL_MAX; -// // --------------------------------------------- -// - for(int y = 0; y < binCountData.size(); y++) { + 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); @@ -216,10 +218,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' + diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index d8d60c2638..2414a2e106 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -50,7 +50,6 @@ namespace Isis { Histogram::Histogram(double minimum, double maximum, int nbins) { SetValidRange(minimum, maximum); - //SetBinRange(minimum, maximum); SetBins(nbins); } @@ -167,21 +166,9 @@ namespace Isis { rangesFromNet(net,statFunc); - - //stretch the domain so that it is an even multiple of binWidth - //for some reason Histogram makes the end points of the bin range be at the center of - //bins. Thus the +/-0.5 forces it to point the bin range at the ends of the bins. - //SetBinRange(binWidth*( floor(this->ValidMinimum()/binWidth )+0.5), - // binWidth*(ceil( this->ValidMaximum()/binWidth )-0.5) ); - - //Keep an eye on this to see if it breaks anything. Also, I need to create //a dataset to give this constructor for the unit test. - //tjw: SetValidRange is moved into SetBinRange - //SetValidRange(binWidth*floor(this->ValidMinimum()/binWidth), - // binWidth*ceil(this->ValidMaximum()/binWidth)); - //from the domain of the data and the requested bin width calculate the number of bins double domain = this->ValidMaximum() - this->ValidMinimum(); int nBins = int ( ceil(domain/binWidth) ); @@ -266,7 +253,6 @@ namespace Isis { //set up the histogram ranges SetValidRange(min, max); - //SetBinRange(min, max); } @@ -396,7 +382,7 @@ namespace Isis { Histogram::~Histogram() { } - //2015-08-24, Tyler Wilson: Added Statistics::SetValidRange call to SetBinRange + //2015-08-24, Tyler Wilson: Added Statistics::SetValidRange call to SetValidRange //So the two functions do not have to be called together when setting //up a histogram @@ -462,8 +448,8 @@ namespace Isis { index = 0; } else { - index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) * - (data[i] - BinRangeStart() ) + 0.5); + index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) * + (data[i] - BinRangeStart()) ); } if (index < 0) index = 0; if (index >= nbins) index = nbins - 1; @@ -490,8 +476,8 @@ namespace Isis { index = 0; } else { - index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart() ) * - (data - BinRangeStart() ) + 0.5); + index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) * + (data - BinRangeStart()) ); } if (index < 0) index = 0; if (index >= nbins) index = nbins - 1; @@ -522,8 +508,8 @@ namespace Isis { index = 0; } else { - index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) * - (data[i] - BinRangeStart()) + 0.5); + index = (int) floor( ((double) nbins / (BinRangeEnd() - BinRangeStart())) * + (data[i] - BinRangeStart()) ); } if (index < 0) index = 0; if (index >= nbins) index = nbins - 1; @@ -591,7 +577,7 @@ namespace Isis { } } - return BinMiddle( (int)p_bins.size() - 1); + return BinMiddle( (int) p_bins.size() - 1); } @@ -653,8 +639,8 @@ namespace Isis { throw IException(IException::Programmer, message, _FILEINFO_); } - double binSize = (BinRangeEnd() - BinRangeStart()) / (double)(p_bins.size() - 1); - low = BinRangeStart() - binSize / 2.0 + binSize * (double) index; + double binSize = (BinRangeEnd() - BinRangeStart()) / (double) p_bins.size(); + low = BinRangeStart() + binSize * (double) index; high = low + binSize; } diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index 5f6c33ddb6..430a82169d 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -81,6 +81,11 @@ namespace Isis { * #1673. * @history 2018-07-27 Jesse Mapel - Added support for initializing a histogram from * signed and unsigned word cubes. References #971. + * @history 2020-06-11 Kaitlyn Lee - Changed how to detemine which bin a pixel/measure falls + * into in AddData(). Changed how the bin range is calculated in + * BinRange(). The math for these functions were incorrect and not + * intuitive. These changes were made alongside changes made + * to cnethist and hist. */ class Histogram : public Statistics { diff --git a/isis/src/control/apps/cnethist/cnethist.xml b/isis/src/control/apps/cnethist/cnethist.xml index a57d7b2e08..860d03cf73 100644 --- a/isis/src/control/apps/cnethist/cnethist.xml +++ b/isis/src/control/apps/cnethist/cnethist.xml @@ -17,6 +17,11 @@ Original version + + Removed "ResidualMagnitude" from the CSV output and added "ResidualMagnitudeMin" and "ResidualMagnitudeMax". This way, the bins are represented by the min/max values of the + bins instead of the DN of the pixel in the middle of the bin. 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 hist. + diff --git a/isis/src/control/apps/cnethist/main.cpp b/isis/src/control/apps/cnethist/main.cpp index 22bd9af0de..6fc5dcc15a 100644 --- a/isis/src/control/apps/cnethist/main.cpp +++ b/isis/src/control/apps/cnethist/main.cpp @@ -39,7 +39,7 @@ void IsisMain() { HistogramPlotWindow *plot=NULL; //setup plot tile and axis labels (if any) - if(ui.IsInteractive()) { + if(ui.IsInteractive()) { // Set the title for the dialog QString title; if(ui.WasEntered("TITLE")) { @@ -70,24 +70,24 @@ void IsisMain() { } QString yaxis = ""; - plot->setAxisLabel(QwtPlot::yRight, yaxis); + plot->setAxisLabel(QwtPlot::yRight, yaxis); } //open text report file (if any) - ofstream fout; - if(!ui.IsInteractive() || ui.WasEntered("TO")) { + ofstream fout; + if(!ui.IsInteractive() || ui.WasEntered("TO")) { // Write the results if(!ui.WasEntered("TO")) { QString msg = "The [TO] parameter must be entered"; throw IException(IException::User, msg, _FILEINFO_); } - QString outfile = ui.GetFileName("TO"); + QString outfile = ui.GetFileName("TO"); fout.open(outfile.toLatin1().data()); } //loop throught the control nets writing reports and drawing histograms as needed - for (int i=0;iAverage() << endl; @@ -121,21 +121,26 @@ void IsisMain() { fout << "Minimum: " << hist->Minimum() << endl; fout << "Maximum: " << hist->Maximum() << endl; fout << "Total Measures: " << hist->TotalPixels() << endl; - + // Write histogram in tabular format fout << endl; - fout << "ResidualMagnitude,MeasuresInBin,CumulativeMeasures,Percent,CumulativePercent" << endl; + fout << "ResidualMagnitudeMin,ResidualMagnitudeMax,MeasuresInBin,CumulativeMeasures,Percent,CumulativePercent" << endl; Isis::BigInt total = 0; double cumpct = 0.0; + double low; + double high; for(int j = 0; j < hist->Bins(); j++) { if(hist->BinCount(j) > 0) { total += hist->BinCount(j); double pct = (double)hist->BinCount(j) / hist->ValidPixels() * 100.; cumpct += pct; - - fout << hist->BinMiddle(j) << ","; + + hist->BinRange(j, low, high); + + fout << low << ","; + fout << high << ","; fout << hist->BinCount(j) << ","; fout << total << ","; fout << pct << ","; @@ -152,9 +157,12 @@ void IsisMain() { if(ui.IsInteractive()) { //Transfer data from histogram to the plotcurve QVector binCountData; + double low; + double high; for(int j = 0; j < hist->Bins(); j++) { if(hist->BinCount(j) > 0) { - binCountData.append(QPointF(hist->BinMiddle(j), hist->BinCount(j))); + hist->BinRange(j, low, high); + binCountData.append(QPointF(low, hist->BinCount(j))); } } @@ -164,13 +172,13 @@ void IsisMain() { QString baseName = FileName(fList[i]).baseName(); histCurve->setTitle(baseName); - + QPen *pen = new QPen(curveColor(i)); pen->setWidth(2); histCurve->setYAxis(QwtPlot::yLeft); - histCurve->setPen(*pen); + histCurve->setPen(*pen); histCurve->setMarkerSymbol(QwtSymbol::NoSymbol); - + histCurve->setData(new QwtPointSeriesData(binCountData)); plot->add(histCurve); From 511dea5a597d7a613a62fc5d53940e7797c372dc Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 8 Sep 2020 11:42:19 -0700 Subject: [PATCH 02/16] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc9a7a6b8..66f1d11c07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ update the Unreleased link so that it compares against the latest release tag. ### Fixed - Equalizer now reports the correct equation and values used to perform the adjustment. [#3987](https://github.com/USGS-Astrogeology/ISIS3/issues/3987) + - 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) ## [4.2.0] - 2020-07-27 From ae559635d8d73b952c69b9300738d5530f30c105 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Fri, 11 Sep 2020 17:45:17 -0700 Subject: [PATCH 03/16] ERROR --- isis/src/base/objs/Histogram/Histogram.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index 2414a2e106..a1c8b096eb 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -663,6 +663,8 @@ namespace Isis { double low, high; BinRange(index, low, high); + printf("%f16\n", low); + printf("%f16\n", high); return (low + high) / 2.0; } From fe817c9b549e4fdee07fe6984efe70de3830bc20 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Fri, 11 Sep 2020 17:45:58 -0700 Subject: [PATCH 04/16] local stats fix --- isis/src/base/apps/stats/stats.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/isis/src/base/apps/stats/stats.xml b/isis/src/base/apps/stats/stats.xml index 986cb66230..8025bb2b2e 100644 --- a/isis/src/base/apps/stats/stats.xml +++ b/isis/src/base/apps/stats/stats.xml @@ -58,6 +58,7 @@ Minimum DN value in the cube Maximum DN value in the cube 65536 +

The cube multiplier and base can be found in the header of the cube. From a33e2393aa12a6f56cb8a1e16f978c75720b2e0f Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Tue, 15 Sep 2020 16:38:26 -0700 Subject: [PATCH 05/16] Added new ImageHistogram class --- isis/src/base/apps/bit2bit/main.cpp | 46 +++++++------- isis/src/base/apps/gaussstretch/main.cpp | 3 +- isis/src/base/apps/histeq/main.cpp | 6 +- isis/src/base/apps/histmatch/main.cpp | 6 +- isis/src/base/apps/isis2raw/main.cpp | 8 +-- isis/src/base/apps/percent/main.cpp | 4 +- isis/src/base/apps/rgb2hsv/main.cpp | 8 +-- isis/src/base/apps/stats/stats.cpp | 4 +- isis/src/base/objs/Cube/Cube.cpp | 20 +++---- isis/src/base/objs/Cube/Cube.h | 14 ++--- isis/src/base/objs/Cube/unitTest.cpp | 60 +++++++++---------- .../objs/GaussianStretch/GaussianStretch.h | 1 + .../base/objs/ProcessExport/ProcessExport.cpp | 4 +- isis/src/base/objs/Stretch/Stretch.cpp | 42 +++++++------ isis/src/base/objs/Stretch/Stretch.h | 11 ++-- isis/src/base/objs/Stretch/unitTest.cpp | 4 +- isis/tests/Mocks.h | 2 +- isis/tests/statsTests.cpp | 12 ++-- 18 files changed, 126 insertions(+), 129 deletions(-) diff --git a/isis/src/base/apps/bit2bit/main.cpp b/isis/src/base/apps/bit2bit/main.cpp index f0077d04b5..b0a9e8e6f6 100644 --- a/isis/src/base/apps/bit2bit/main.cpp +++ b/isis/src/base/apps/bit2bit/main.cpp @@ -1,13 +1,13 @@ #include "Isis.h" #include "ProcessByLine.h" #include "SpecialPixel.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "UserInterface.h" #include "Pvl.h" #include "Cube.h" #include "Process.h" -using namespace std; +using namespace std; using namespace Isis; void populate(Buffer &in, Buffer &out); @@ -15,28 +15,28 @@ void populate(Buffer &in, Buffer &out); void IsisMain(){ UserInterface &ui = Application::GetUserInterface(); - + //We will process by line ProcessByLine p; Cube* cubeptr = p.SetInputCube("FROM"); - + // Histogram* histptr = (cubeptr -> Histogram()); double max = ui.GetDouble("MAXVAL"); double min = ui.GetDouble("MINVAL"); - + /* A histogram is made from the input cube, as the default min of the bit2bit output is at .5% of the data range, and the default max is at 99.5% - */ - Histogram* histptr = cubeptr -> histogram(); - + */ + ImageHistogram* histptr = cubeptr -> histogram(); + double maxper = histptr -> Percent(ui.GetDouble("MAXPER")); double minper = histptr -> Percent(ui.GetDouble("MINPER")); double validMin = Isis::ValidMinimum; double validMax = Isis::ValidMaximum; - - + + // Set properties MIN,MAX, and PixelType for output cube CubeAttributeOutput outputProperties; @@ -60,26 +60,26 @@ void IsisMain(){ } else { outputProperties.setPixelType(Real); - } + } if(ui.GetBoolean("STATS")) { //! Run extended statistics Cube* ocubeptr = p.SetOutputCube (ui.GetFileName("TO"),outputProperties, cubeptr->sampleCount(),cubeptr->lineCount(), cubeptr->bandCount()); - + p.StartProcess(populate); - - Histogram* ohistptr = (ocubeptr -> histogram(1,validMin,validMax)); + + ImageHistogram* ohistptr = (ocubeptr -> histogram(1,validMin,validMax)); int iLrs = histptr -> LrsPixels(); int iHrs = histptr -> HrsPixels(); int iNull = histptr -> NullPixels(); int oLrs = ohistptr -> LrsPixels(); int oHrs = ohistptr -> HrsPixels(); - int oNull = ohistptr -> NullPixels(); + int oNull = ohistptr -> NullPixels(); double invalid_pi = (( (histptr -> TotalPixels()) - (histptr -> ValidPixels()))*100.0) / ((histptr -> TotalPixels())*1.0); - double invalid_po = (( (ohistptr -> TotalPixels()) - (ohistptr -> ValidPixels()))*100.0) / ((ohistptr -> TotalPixels())*1.0); - + double invalid_po = (( (ohistptr -> TotalPixels()) - (ohistptr -> ValidPixels()))*100.0) / ((ohistptr -> TotalPixels())*1.0); + p.EndProcess(); //!Write bit2bit summary to the screen @@ -95,7 +95,7 @@ void IsisMain(){ cout << " HRS:\t\t" << oHrs << endl; cout << " NULL:\t\t" << oNull << endl; cout << " Invalid Pixel %:\t\t" << invalid_po << endl<< endl; - + //!Write bit2bit summary to print.prt logfile PvlGroup results("bit2bit_Results"); results += PvlKeyword ("INPUT_LRS",toString(iLrs)); @@ -109,16 +109,16 @@ void IsisMain(){ results += PvlKeyword ("OUTPUT_NULL",toString(oNull)); results += PvlKeyword ("OUTPUT_INVALID_PERCENT",toString(invalid_po)); Application::Log(results); - + delete histptr; - delete ohistptr; + delete ohistptr; } else{ //! run minimal statistics (runs faster) int iLrs = histptr -> LrsPixels(); int iHrs = histptr -> HrsPixels(); int iNull = histptr -> NullPixels(); double invalid_pi = (( (histptr -> TotalPixels()) - (histptr -> ValidPixels()))*100.0) / ((histptr -> TotalPixels())*1.0); - + p.EndProcess(); //!Write bit2bit summary to the screen @@ -131,7 +131,7 @@ void IsisMain(){ cout << " Data Range:\t\t"; cout << validMin << " < x < " << validMax << endl; - + //!Write bit2bit summary to print.prt logfile PvlGroup results("bit2bit_Results"); results += PvlKeyword ("INPUT_LRS",toString(iLrs)); @@ -141,7 +141,7 @@ void IsisMain(){ results += PvlKeyword ("OUTPUT_MIN",toString(validMin)); results += PvlKeyword ("OUTPUT_MAX",toString(validMax)); Application::Log(results); - + delete histptr; } } diff --git a/isis/src/base/apps/gaussstretch/main.cpp b/isis/src/base/apps/gaussstretch/main.cpp index eed8bf3a72..321b0bb913 100644 --- a/isis/src/base/apps/gaussstretch/main.cpp +++ b/isis/src/base/apps/gaussstretch/main.cpp @@ -17,7 +17,7 @@ void IsisMain() { double gsigma = Isis::Application::GetUserInterface().GetDouble("GSIGMA"); for(int i = 0; i < icube->bandCount(); i++) { - Histogram hist = *(icube->histogram(i + 1)); + ImageHistogram 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)); @@ -36,4 +36,3 @@ void gauss(Buffer &in, Buffer &out) { out[i] = stretch[in.Band(i)-1]->Map(in[i]); } } - diff --git a/isis/src/base/apps/histeq/main.cpp b/isis/src/base/apps/histeq/main.cpp index 896c6cdc28..c61f1c0876 100644 --- a/isis/src/base/apps/histeq/main.cpp +++ b/isis/src/base/apps/histeq/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "Statistics.h" #include "Stretch.h" -#include "Histogram.h" +#include "ImageHistogram.h" using namespace std; using namespace Isis; @@ -25,8 +25,8 @@ void IsisMain() { int increment = ui.GetInteger("INCREMENT"); // Histograms from input cubes - Histogram *from = icube->histogram(); - Histogram *match = icube->histogram(); + ImageHistogram *from = icube->histogram(); + ImageHistogram *match = icube->histogram(); double fromMin = from->Percent(minimum); double fromMax = from->Percent(maximum); diff --git a/isis/src/base/apps/histmatch/main.cpp b/isis/src/base/apps/histmatch/main.cpp index 66e1978bd7..c4147d1639 100644 --- a/isis/src/base/apps/histmatch/main.cpp +++ b/isis/src/base/apps/histmatch/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "Statistics.h" #include "Stretch.h" -#include "Histogram.h" +#include "ImageHistogram.h" using namespace std; using namespace Isis; @@ -16,10 +16,10 @@ void IsisMain() { // Setup the input and output cubes along with histograms ProcessByLine p; Cube *mcube = p.SetInputCube("MATCH", Isis::OneBand); - Histogram *match = mcube->histogram(); + ImageHistogram *match = mcube->histogram(); p.ClearInputCubes(); Cube *icube = p.SetInputCube("FROM", Isis::OneBand); - Histogram *from = icube->histogram(); + ImageHistogram *from = icube->histogram(); p.SetOutputCube("TO"); // Histogram specifications diff --git a/isis/src/base/apps/isis2raw/main.cpp b/isis/src/base/apps/isis2raw/main.cpp index 74cbed6491..01c2ef81c5 100644 --- a/isis/src/base/apps/isis2raw/main.cpp +++ b/isis/src/base/apps/isis2raw/main.cpp @@ -6,7 +6,7 @@ #include #include -#include "Histogram.h" +#include "ImageHistogram.h" #include "ProcessExport.h" #include "UserInterface.h" #include "SpecialPixel.h" @@ -34,7 +34,7 @@ void IsisMain() { // Applies the input to output stretch options if(ui.GetString("STRETCH") == "LINEAR") { -// if(ui.GetString("BITTYPE") != "32BIT") + // if(ui.GetString("BITTYPE") != "32BIT") p.SetInputRange(); } if(ui.GetString("STRETCH") == "MANUAL") { @@ -68,7 +68,7 @@ void IsisMain() { p.SetOutputType(Isis::Real); pixType = NONE; } - + if (ui.GetString("STRETCH") != "NONE" || ui.GetString("BITTYPE") != "32BIT") { checkRange(ui, min, max); } @@ -119,7 +119,7 @@ void IsisMain() { // Validates provided range void checkRange(UserInterface &ui, double &min, double &max) { - Isis::Histogram *hist = p_cube->histogram(0); + Isis::ImageHistogram *hist = p_cube->histogram(0); if(ui.WasEntered("OMIN")) { if(ui.GetDouble("OMIN") < min) { diff --git a/isis/src/base/apps/percent/main.cpp b/isis/src/base/apps/percent/main.cpp index 378c2713b4..278f41c5b7 100644 --- a/isis/src/base/apps/percent/main.cpp +++ b/isis/src/base/apps/percent/main.cpp @@ -6,7 +6,7 @@ #include "Process.h" #include "Pvl.h" #include "PvlFormat.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "IString.h" @@ -32,7 +32,7 @@ void IsisMain() { for(int i = 0; i < tokens.size(); i++) { double percentage = toDouble(tokens[i]); // Obtain the Histogram and the value at the percentage - Histogram *hist = icube->histogram(); + ImageHistogram *hist = icube->histogram(); double value = hist->Percent(percentage); kwPercent += toString(percentage); kwValue += toString(value); diff --git a/isis/src/base/apps/rgb2hsv/main.cpp b/isis/src/base/apps/rgb2hsv/main.cpp index c2b3c45316..07d07c2994 100644 --- a/isis/src/base/apps/rgb2hsv/main.cpp +++ b/isis/src/base/apps/rgb2hsv/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "QColor" -#include "Histogram.h" +#include "ImageHistogram.h" #include "Stretch.h" using namespace std; @@ -34,9 +34,9 @@ void IsisMain() { // Automatic is selected if(ui.GetString("MODE") == "AUTOMATIC") { - Histogram *redHist = redCube->histogram(); - Histogram *greenHist = greenCube->histogram(); - Histogram *blueHist = blueCube->histogram(); + ImageHistogram *redHist = redCube->histogram(); + ImageHistogram *greenHist = greenCube->histogram(); + ImageHistogram *blueHist = blueCube->histogram(); rMin = redHist->Percent(ui.GetDouble("RMINPER")); rMax = redHist->Percent(ui.GetDouble("RMAXPER")); diff --git a/isis/src/base/apps/stats/stats.cpp b/isis/src/base/apps/stats/stats.cpp index d192551a25..7841f03025 100644 --- a/isis/src/base/apps/stats/stats.cpp +++ b/isis/src/base/apps/stats/stats.cpp @@ -7,7 +7,7 @@ #include "CubeAttribute.h" #include "Cube.h" #include "FileName.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "Pvl.h" #include "UserInterface.h" @@ -116,7 +116,7 @@ namespace Isis { int bandCount = cube->bandCount(); for (int i = 1; i <= bandCount; i++) { - Histogram *stats = cube->histogram(i, validMin, validMax); + ImageHistogram *stats = cube->histogram(i, validMin, validMax); // Construct a label with the results PvlGroup results("Results"); diff --git a/isis/src/base/objs/Cube/Cube.cpp b/isis/src/base/objs/Cube/Cube.cpp index 5273e29e74..8ee1366454 100644 --- a/isis/src/base/objs/Cube/Cube.cpp +++ b/isis/src/base/objs/Cube/Cube.cpp @@ -40,7 +40,7 @@ #include "CubeTileHandler.h" #include "Endian.h" #include "FileName.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "IException.h" #include "LineManager.h" #include "Message.h" @@ -106,7 +106,7 @@ namespace Isis { * * @param fileName Name of the cube file to open. Environment * variables in the filename will be automatically expanded. - * @param label PVL label object representing the new Cube label + * @param label PVL label object representing the new Cube label * @param isd JSON object containing Ale compatible ISD * @param access Defines how the cube will be opened. Either read-only * "r" or read-write "rw". @@ -118,7 +118,7 @@ namespace Isis { close(); open(fileName.toString(), access); } - + /** * Initialize Cube data from a PVL label and JSON ISD. * @@ -132,15 +132,15 @@ namespace Isis { void Cube::fromIsd(const FileName &fileName, FileName &labelFile, FileName &isdFile, QString access) { std::ifstream isdStream(isdFile.expanded().toStdString()); std::ifstream labelStream(labelFile.expanded().toStdString()); - + Pvl label; nlohmann::json isd; - + isdStream >> isd; labelStream >> label; - + fromIsd(fileName, label, isd, access); - reopen("rw"); + reopen("rw"); } //! Destroys the Cube object. @@ -1381,7 +1381,7 @@ namespace Isis { * @throws IsisProgrammerError Band was less than zero or more than the number * of bands in the cube. */ - Histogram *Cube::histogram(const int &band, QString msg) { + ImageHistogram *Cube::histogram(const int &band, QString msg) { return histogram(band, ValidMinimum, ValidMaximum, msg); } @@ -1411,7 +1411,7 @@ namespace Isis { * @throws ProgrammerError Band was less than zero or more than the number * of bands in the cube. */ - Histogram *Cube::histogram(const int &band, const double &validMin, + ImageHistogram *Cube::histogram(const int &band, const double &validMin, const double &validMax, QString msg) { // Make sure cube is open if ( !isOpen() ) { @@ -1435,7 +1435,7 @@ namespace Isis { } Progress progress; - Histogram *hist = new Histogram(*this, band, &progress); + ImageHistogram *hist = new ImageHistogram(*this, band, &progress); LineManager line(*this); // This range is for throwing out data; the default parameters are OK always diff --git a/isis/src/base/objs/Cube/Cube.h b/isis/src/base/objs/Cube/Cube.h index 595d9683e5..d14d72040c 100644 --- a/isis/src/base/objs/Cube/Cube.h +++ b/isis/src/base/objs/Cube/Cube.h @@ -49,7 +49,7 @@ namespace Isis { class Pvl; class PvlGroup; class Statistics; - class Histogram; + class ImageHistogram; /** * @brief IO Handler for Isis Cubes. @@ -173,7 +173,7 @@ namespace Isis { public: Cube(); Cube(const FileName &fileName, QString access = "r"); - + virtual ~Cube(); /** @@ -284,11 +284,11 @@ namespace Isis { FileName externalCubeFileName() const; virtual QString fileName() const; Format format() const; - virtual Histogram *histogram(const int &band = 1, - QString msg = "Gathering histogram"); - virtual Histogram *histogram(const int &band, const double &validMin, - const double &validMax, - QString msg = "Gathering histogram"); + virtual ImageHistogram *histogram(const int &band = 1, + QString msg = "Gathering histogram"); + virtual ImageHistogram *histogram(const int &band, const double &validMin, + const double &validMax, + QString msg = "Gathering histogram"); Pvl *label() const; int labelSize(bool actual = false) const; int lineCount() const; diff --git a/isis/src/base/objs/Cube/unitTest.cpp b/isis/src/base/objs/Cube/unitTest.cpp index fe1bbde4f4..6cbff8c575 100644 --- a/isis/src/base/objs/Cube/unitTest.cpp +++ b/isis/src/base/objs/Cube/unitTest.cpp @@ -11,7 +11,7 @@ #include "LineManager.h" #include "Pvl.h" #include "Preference.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "SpecialPixel.h" #include "Statistics.h" @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) { // Test Histogram object on a single band, 1 by default cerr << "Testing histogram method, band 1 ... " << endl; - Histogram *bandOneHist = in.histogram(); + ImageHistogram *bandOneHist = in.histogram(); cerr << "Average: " << bandOneHist->Average() << endl; cerr << "Standard Dev: " << bandOneHist->StandardDeviation() << endl; cerr << "Mode: " << bandOneHist->Mode() << endl; @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) { // Test histogram object on all bands cerr << "Testing histogram method, all bands ... " << endl; - Histogram *allBandsHistogram = in.histogram(0); + ImageHistogram *allBandsHistogram = in.histogram(0); cerr << "Average: " << allBandsHistogram->Average() << endl; cerr << "Standard Dev: " << allBandsHistogram->StandardDeviation() << endl; cerr << "Mode: " << allBandsHistogram->Mode() << endl; @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) { catch (IException &e) { e.print(); } - + // Check error for histogram object on a closed cube try { // out has already been closed @@ -216,9 +216,9 @@ int main(int argc, char *argv[]) { { e.print(); } - + cerr << endl; - + // Test statistics object on a single band, 1 by default cerr << "Testing statistics method, band 1 ... " << endl; Statistics *bandOneStats = in.statistics(); @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) { catch (IException &e) { e.print(); } - + // Check error for statistics object on a closed cube try { // out has already been closed @@ -294,7 +294,7 @@ int main(int argc, char *argv[]) { boundaryTestCube.create("IsisCube_boundary"); Report(boundaryTestCube); LineManager boundaryLine(boundaryTestCube); - + for(boundaryLine.begin(); !boundaryLine.end(); boundaryLine++) { for(int i = 0; i < boundaryLine.size(); i++) { boundaryLine[i] = 1.0; @@ -353,7 +353,7 @@ int main(int argc, char *argv[]) { // Read after the bands start in the cube. readBrick.SetBasePosition(1, 1, 4); boundaryTestCube.read(readBrick); - + if (readBrick[0] != 1.0) { cerr << "\t\t Value inside cube boundary was not 1.0." << endl; return 1; @@ -461,8 +461,8 @@ int main(int argc, char *argv[]) { } cerr << endl; boundaryTestCube.close(); - - + + // Test cube where its chunk size is the same as its buffer shape cerr << "Testing one line BSQ cube (where chunk dimensions == buffer shape) ... " << endl; cerr << "Constructing cube ... " << endl << endl; @@ -472,7 +472,7 @@ int main(int argc, char *argv[]) { bsqOneLineTestCube.create("IsisCube_bsqOneLine"); Report(bsqOneLineTestCube); LineManager oneLine(bsqOneLineTestCube); - + // our cube will be 1, 2, 3 // 2, 3, 4 // 3, 4, 5 @@ -483,10 +483,10 @@ int main(int argc, char *argv[]) { bsqOneLineTestCube.write(oneLine); } bsqOneLineTestCube.close(); - + // Simulate reading of an S x 1 x B cube Brick readLineBrick(3, 1, 1, bsqOneLineTestCube.pixelType()); - + // Test reading repeated ascending virtual bands cerr << "Testing reading ascending repeating virtual bands (1, 2, 2, 3)... " << endl; virtualBands.clear(); @@ -501,7 +501,7 @@ int main(int argc, char *argv[]) { bsqOneLineTestCube.read(readLineBrick); for (int i = 0; i < readLineBrick.size(); i++) { if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) { - cerr << "Virtual bands accessed incorrectly at brick band " + cerr << "Virtual bands accessed incorrectly at brick band " << readLineBrick.Band() << endl; return 1; } @@ -509,7 +509,7 @@ int main(int argc, char *argv[]) { } cerr << endl; bsqOneLineTestCube.close(); - + // Test reading skipped ascending virtual bands cerr << "Testing reading skipped ascending virtual bands (1, 3, 3)... " << endl; virtualBands.clear(); @@ -523,7 +523,7 @@ int main(int argc, char *argv[]) { bsqOneLineTestCube.read(readLineBrick); for (int i = 0; i < readLineBrick.size(); i++) { if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) { - cerr << "Virtual bands accessed incorrectly at virtual band " + cerr << "Virtual bands accessed incorrectly at virtual band " << virtualBands[readLineBrick.Band() - 1] << endl; return 1; } @@ -531,7 +531,7 @@ int main(int argc, char *argv[]) { } cerr << endl; bsqOneLineTestCube.close(); - + // Test reading outside boundaries cerr << "Testing reading outside of cube boundaries with virtual bands (1, 5)... " << endl; virtualBands.clear(); @@ -545,14 +545,14 @@ int main(int argc, char *argv[]) { for (int i = 0; i < readLineBrick.size(); i++) { if (readLineBrick.Band() == 1) { if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) { - cerr << "Virtual bands accessed incorrectly at virtual band " + cerr << "Virtual bands accessed incorrectly at virtual band " << virtualBands[readLineBrick.Band() - 1] << endl; return 1; } } else { if (readLineBrick[i] != Null) { - cerr << "Value outside cube boundary at virtual band " + cerr << "Value outside cube boundary at virtual band " << virtualBands[readLineBrick.Band() - 1] << endl; } } @@ -560,7 +560,7 @@ int main(int argc, char *argv[]) { } cerr << endl; bsqOneLineTestCube.close(); - + // Test reading descending bands cerr << "Testing reading descending virtual bands (3, 1, 3)... " << endl; virtualBands.clear(); @@ -574,7 +574,7 @@ int main(int argc, char *argv[]) { bsqOneLineTestCube.read(readLineBrick); for (int i = 0; i < readLineBrick.size(); i++) { if (readLineBrick[i] != (i + virtualBands[readLineBrick.Band()-1].toInt())) { - cerr << "Virtual bands accessed incorrectly at virtual band " + cerr << "Virtual bands accessed incorrectly at virtual band " << virtualBands[readLineBrick.Band() - 1] << endl; return 1; } @@ -582,8 +582,8 @@ int main(int argc, char *argv[]) { } cerr << endl; bsqOneLineTestCube.close(); - - + + // Test creating a bsq cube that exceeds 1GB sample size limit to test CubeBsqHandler cerr << "Testing creating large BSQ where samples exceed 1GB chunk size limit ... " << endl; cerr << "Constructing cube ... " << endl << endl; @@ -597,10 +597,10 @@ int main(int argc, char *argv[]) { cerr << endl; largebsqTestCube.close(); - - + + // Test bsq cube that has a linecount > maximum chunk line size to test CubeBsqHandler - cerr << "Testing creating BSQ cube where size of sample pixels exceeds cube's lineCount ... " + cerr << "Testing creating BSQ cube where size of sample pixels exceeds cube's lineCount ... " << endl; cerr << "Constructing cube ... " << endl << endl; Cube bsqTestCube; @@ -609,11 +609,11 @@ int main(int argc, char *argv[]) { bsqTestCube.setFormat(Cube::Bsq); bsqTestCube.create("IsisCube_bsq"); Report(bsqTestCube); - + cerr << endl; bsqTestCube.close(); - - + + // Check errors cerr << "Testing errors ... " << endl; try { diff --git a/isis/src/base/objs/GaussianStretch/GaussianStretch.h b/isis/src/base/objs/GaussianStretch/GaussianStretch.h index d194954b90..b114b2f2fa 100644 --- a/isis/src/base/objs/GaussianStretch/GaussianStretch.h +++ b/isis/src/base/objs/GaussianStretch/GaussianStretch.h @@ -25,6 +25,7 @@ #include "Statistics.h" #include "Histogram.h" +#include "ImageHistogram.h" #include "Stretch.h" #include "IException.h" #include "Constants.h" diff --git a/isis/src/base/objs/ProcessExport/ProcessExport.cpp b/isis/src/base/objs/ProcessExport/ProcessExport.cpp index 251c06db05..85c035637b 100644 --- a/isis/src/base/objs/ProcessExport/ProcessExport.cpp +++ b/isis/src/base/objs/ProcessExport/ProcessExport.cpp @@ -30,7 +30,7 @@ #include "LineManager.h" #include "BandManager.h" #include "SpecialPixel.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "Stretch.h" #include "Application.h" #include "EndianSwapper.h" @@ -388,7 +388,7 @@ namespace Isis { // Or get the automatic parameters else if (strType != "NONE") { - Isis::Histogram *hist = InputCubes[i]->histogram(0); + Isis::ImageHistogram *hist = InputCubes[i]->histogram(0); p_inputMinimum.push_back(hist->Percent( Application::GetUserInterface().GetDouble("MINPERCENT"))); p_inputMaximum.push_back(hist->Percent( diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index a16f37379b..753c9f800f 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -25,7 +25,7 @@ #include #include "Stretch.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "IString.h" #include "SpecialPixel.h" #include "IException.h" @@ -53,9 +53,9 @@ namespace Isis { /** * Constructs a Stretch object with default mapping of special pixel values to - * themselves and a provided name. - * - * @param name Name to use for Stretch + * themselves and a provided name. + * + * @param name Name to use for Stretch */ Stretch::Stretch(QString name) : Blob(name, "Stretch") { p_null = Isis::NULL8; @@ -251,7 +251,7 @@ namespace Isis { * * @throws Isis::IException::User - invalid stretch pair */ - void Stretch::Parse(const QString &pairs, const Isis::Histogram *hist) { + void Stretch::Parse(const QString &pairs, const Isis::ImageHistogram *hist) { // Zero out the stretch arrays p_input.clear(); p_output.clear(); @@ -433,11 +433,11 @@ namespace Isis { /** - * Read saved Stretch data from a Cube into this object. - * - * This is called by Blob::Read() and is the actual data reading function - * ultimately called when running something like cube->read(stretch); - * + * Read saved Stretch data from a Cube into this object. + * + * This is called by Blob::Read() and is the actual data reading function + * ultimately called when running something like cube->read(stretch); + * * @param is input stream containing the saved Stretch information */ void Stretch::ReadData(std::istream &is) { @@ -475,8 +475,8 @@ namespace Isis { /** * Get the Type of Stretch. This is only used by the AdvancedStretchTool. - * - * @return QString Type of Stretch. + * + * @return QString Type of Stretch. */ QString Stretch::getType(){ return p_type; @@ -485,8 +485,8 @@ namespace Isis { /** * Set the Type of Stretch. This is only used by the AdvancedStretchTool. - * - * @param stretchType The type of stretch. + * + * @param stretchType The type of stretch. */ void Stretch::setType(QString stretchType){ // check to see if valid input @@ -498,16 +498,16 @@ namespace Isis { * Initializes for writing stretch to cube blob */ void Stretch::WriteInit() { - p_nbytes = Text().toStdString().size(); + p_nbytes = Text().toStdString().size(); } /** - * Writes the stretch information to a cube. - * - * This is called by Blob::write() and is ultimately the function - * called when running something like cube->write(stretch); - * + * Writes the stretch information to a cube. + * + * This is called by Blob::write() and is ultimately the function + * called when running something like cube->write(stretch); + * * @param os output stream to write the stretch data to. */ void Stretch::WriteData(std::fstream &os) { @@ -515,5 +515,3 @@ namespace Isis { } } // end namespace isis - - diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index 5da48bbe74..ddb5b6362d 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -25,7 +25,7 @@ #include #include #include "Pvl.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "Blob.h" namespace Isis { @@ -69,7 +69,7 @@ namespace Isis { * input side is a perentage. Fixed Input and Output getters * to check both sides of boundry condition for valid data * @history 2020-02-27 Kristin Berry - Updated to inherit from Blob so Stretches can be - * saved and restored from cubes. + * saved and restored from cubes. */ class Stretch : public Isis::Blob { private: @@ -173,7 +173,7 @@ namespace Isis { double Map(const double value) const; void Parse(const QString &pairs); - void Parse(const QString &pairs, const Isis::Histogram *hist); + void Parse(const QString &pairs, const Isis::ImageHistogram *hist); QString Text() const; @@ -182,8 +182,8 @@ namespace Isis { return p_pairs; }; - QString getType(); - void setType(QString type); + QString getType(); + void setType(QString type); double Input(const int index) const; double Output(const int index) const; @@ -205,4 +205,3 @@ namespace Isis { }; #endif - diff --git a/isis/src/base/objs/Stretch/unitTest.cpp b/isis/src/base/objs/Stretch/unitTest.cpp index 05fba2d851..a73a6b039c 100644 --- a/isis/src/base/objs/Stretch/unitTest.cpp +++ b/isis/src/base/objs/Stretch/unitTest.cpp @@ -91,8 +91,8 @@ int main() { // test the Parse for when inputs are %'s cout << endl << "Testing new Parse that takes %'s for input side of pairs" << endl; - Histogram temp(0.0, 100.0, 101); - Histogram *h = &temp; + ImageHistogram temp(0.0, 100.0, 101); + ImageHistogram *h = &temp; for(double i = 0.0; i <= 100.0; i++) { h->AddData(&i, 1); } diff --git a/isis/tests/Mocks.h b/isis/tests/Mocks.h index 12a3c3d48a..dda06c742c 100644 --- a/isis/tests/Mocks.h +++ b/isis/tests/Mocks.h @@ -18,7 +18,7 @@ class MockCube : public Cube { MOCK_CONST_METHOD0(bandCount, int()); MOCK_CONST_METHOD0(fileName, QString()); MOCK_CONST_METHOD1(physicalBand, int(const int &virtualBand)); - MOCK_METHOD4(histogram, Histogram*( + MOCK_METHOD4(histogram, ImageHistogram*( const int &band, const double &validMin, const double &validMax, QString msg)); diff --git a/isis/tests/statsTests.cpp b/isis/tests/statsTests.cpp index a5527064c2..ff027fb0f3 100644 --- a/isis/tests/statsTests.cpp +++ b/isis/tests/statsTests.cpp @@ -6,7 +6,7 @@ #include "Cube.h" #include "FileName.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "Pvl.h" #include "SpecialPixel.h" @@ -17,7 +17,7 @@ class MockCube : public Cube { MOCK_CONST_METHOD0(bandCount, int()); MOCK_CONST_METHOD0(fileName, QString()); MOCK_CONST_METHOD1(physicalBand, int(const int &virtualBand)); - MOCK_METHOD4(histogram, Histogram*( + MOCK_METHOD4(histogram, ImageHistogram*( const int &band, const double &validMin, const double &validMax, QString msg)); @@ -48,13 +48,13 @@ class stats_MockHist : public ::testing::Test { void SetUp() override { mockCube = nullptr; - Histogram *testBand1Stats = new Histogram(-10, 10, 21); + ImageHistogram *testBand1Stats = new ImageHistogram(-10, 10, 21); for (int val = -10; val <=10; val++) { testBand1Stats->AddData(val); } testBand1Stats->AddData(0.0); - Histogram *testBand2Stats = new Histogram(-10, 10, 21); + ImageHistogram *testBand2Stats = new ImageHistogram(-10, 10, 21); testBand2Stats->AddData(Null); testBand2Stats->AddData(Lrs); testBand2Stats->AddData(Lis); @@ -146,7 +146,7 @@ TEST_F(stats_MockHist, TestStats) { } TEST(stats, ValidMinimum) { - Histogram *testStats = new Histogram(-1000,1000); + ImageHistogram *testStats = new ImageHistogram(-1000,1000); MockCube *mockCube = new MockCube(); EXPECT_CALL(*mockCube, bandCount()) @@ -173,7 +173,7 @@ TEST(stats, ValidMinimum) { } TEST(stats, ValidMaximum) { - Histogram *testStats = new Histogram(-1000,1000); + ImageHistogram *testStats = new ImageHistogram(-1000,1000); MockCube *mockCube = new MockCube(); EXPECT_CALL(*mockCube, bandCount()) From 7782a6b74e31d78855b2711644c6db650e0a9e34 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Tue, 15 Sep 2020 16:43:35 -0700 Subject: [PATCH 06/16] Actually added the ImageHistogram class --- .../objs/ImageHistogram/ImageHistogram.cpp | 225 ++++++++++++++++++ .../base/objs/ImageHistogram/ImageHistogram.h | 87 +++++++ isis/src/base/objs/ImageHistogram/Makefile | 7 + 3 files changed, 319 insertions(+) create mode 100644 isis/src/base/objs/ImageHistogram/ImageHistogram.cpp create mode 100644 isis/src/base/objs/ImageHistogram/ImageHistogram.h create mode 100644 isis/src/base/objs/ImageHistogram/Makefile diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp new file mode 100644 index 0000000000..cd21cd6450 --- /dev/null +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp @@ -0,0 +1,225 @@ +/** + * @file + * $Revision: 1.4 $ + * $Date: 2008/08/15 22:03:32 $ + * + * Unless noted otherwise, the portions of Isis written by the USGS are + * public domain. See individual third-party library and package descriptions + * for intellectual property information, user agreements, and related + * information. + * + * Although Isis has been used by the USGS, no warranty, expressed or + * implied, is made by the USGS as to the accuracy and functioning of such + * software and related material nor shall the fact of distribution + * constitute any such warranty, and no responsibility is assumed by the + * USGS in connection therewith. + * + * For additional information, launch + * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html + * in a browser or see the Privacy & Disclaimers page on the Isis website, + * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on + * http://www.usgs.gov/privacy.html. + */ +#include "ImageHistogram.h" + +#include "ControlNet.h" +#include "ControlMeasure.h" + +#include +#include +#include +#include + +using namespace std; + +namespace Isis { + + /** + * Constructs a histogram object. Only data between the minimum and maximum + * will be binned, and the bin range will be from the minimum to the maximum. + * + * @param minimum Minimum value for binning the data into the histogram. + * @param maximum Maximum value for binning the data into the histogram. + * @param nbins The number of bins to use + */ + ImageHistogram::ImageHistogram(double minimum, double maximum, int nbins) : + Histogram(minimum, maximum, nbins) { + } + + + /** + * Constructs a histogram object using a cube. This constructor computes + * the minimum, maximum for the binning range and number of bins + * automatically. All statistics will still be collected, though data at + * either end of the histogram will be put into one bin in order to attempt to + * achieve better histogram statistics. + * + * TODO: progress needs to be a bool. + * + * @param cube The cube to used to determine min/max and bins + * @param statsBand The band number the histogram will be collected from + * @param progress The Progress object to be used to output the percent + * processed information + * @param startSample The sample to start reading cube data from + * @param startLine The line to start reading cube data from + * @param endSample The sample to stop reading cube data at (Null for nsamps) + * @param endLine The line to stop reading cube data at (Null for nlines) + * @param bins The number of histogram bins to create (0 for automatic) + * @param addCubeData True to fill the histogram with data in addition to + * initializing the binning ranges. + */ + ImageHistogram::ImageHistogram(Cube &cube, int statsBand, Progress *progress, + double startSample, double startLine, + double endSample, double endLine, + int bins, bool addCubeData) : + Histogram(cube, statsBand, progress, + startSample, startLine, + endSample, endLine, + bins, addCubeData) { + } + + + /** + * Constructs a histogram from a control netowrk + * + * @param net: Reference to a ControlNetwork used to access all the measures. + * @param statFunc: Pointer to a ControlMeasure acessor, the returns of this + * function call will be used to build up the network. + * @param bins: The number of bins to divide the histogram into. + * @throws The number of Histogram Bins must be greater than 0. + */ + ImageHistogram::ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, int bins) : + Histogram(net, statFunc, bins){ + } + + + /** + * Constructs a histogram from a control netowrk + * + * @param Net: Reference to a ControlNetwork used to access all the measures. + * @param statFunc: Pointer to a ControlMeasure acessor, the returns of this. + * function call will be used to build up the network. + * @param binWidth: The width of histogram bins. + * @throws The width of Histogram Bins must be greater than 0. + */ + ImageHistogram::ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, + double binWidth) : + Histogram(net, statFunc, binWidth) { + } + + + //! Destructs a histogram object. + ImageHistogram::~ImageHistogram() { + } + + /** + * Add an array of doubles to the histogram counters. This method can be + * invoked multiple times. For example, once for each line in a cube, before + * obtaining statistics and histogram information. + * + * @param data Pointer to array of double to add. + * @param count Number of doubles to process. + */ + void ImageHistogram::AddData(const double *data, + const unsigned int count) { + Statistics::AddData(data, count); + + int nbins = p_bins.size(); + int index; + for (unsigned int i = 0; i < count; i++) { + if (IsValidPixel(data[i]) && InRange(data[i]) ) { + if (BinRangeStart() == BinRangeEnd() ) { + index = 0; + } + else { + index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) * + (data[i] - BinRangeStart() ) + 0.5); + } + if (index < 0) index = 0; + if (index >= nbins) index = nbins - 1; + p_bins[index] += 1; + } + } + } + + /** + * Add a single double data to the histogram. Of course this can be invoke multiple times. + * e.g. once for each residual in a network for instance. + * + * @param data a single observation to be added to the histogram + */ + void ImageHistogram::AddData(const double data) { + Statistics::AddData(data); + + int nbins = p_bins.size(); + int index; + if (IsValidPixel(data) && InRange(data) ) { + if (BinRangeStart() == BinRangeEnd() ) { + index = 0; + } + else { + index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart() ) * + (data - BinRangeStart() ) + 0.5); + } + if (index < 0) index = 0; + if (index >= nbins) index = nbins - 1; + p_bins[index] += 1; + } + } + + /** + * Remove an array of doubles from the histogram counters. Note that this + * invalidates the absolute minimum and maximum. They will no longer be + * useable. + * @see Stats + * + * @param data Pointer to array of doubles to remove. + * @param count number of doubles to process. + */ + void ImageHistogram::RemoveData(const double *data, + const unsigned int count) { + Statistics::RemoveData(data, count); + + int nbins = p_bins.size(); + int index; + for (unsigned int i = 0; i < count; i++) { + if (IsValidPixel(data[i]) ) { + + if (BinRangeStart() == BinRangeEnd() ) { + index = 0; + } + else { + index = (int) floor((double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) * + (data[i] - BinRangeStart()) + 0.5); + } + if (index < 0) index = 0; + if (index >= nbins) index = nbins - 1; + p_bins[index] -= 1; + } + } + } + + /** + * Returns the left edge and right edge values of a bin. That is the range of + * data the bin covers. + * + * @throws iException The programmer has passed in an index outside of 0 + * to Bins()-1. + * + * @param index Index of the desired bin 0 to Bins()-1. + * @param low The value at the left edge of the requested bin. + * @param high The value at the right edge of the requested bin. + */ + void ImageHistogram::BinRange(const int index, + double &low, double &high) const { + if ( (index < 0) || (index >= (int)p_bins.size() ) ) { + + QString message = Message::ArraySubscriptNotInRange(index); + throw IException(IException::Programmer, message, _FILEINFO_); + } + + double binSize = (BinRangeEnd() - BinRangeStart()) / (double)(p_bins.size() - 1); + low = BinRangeStart() - binSize / 2.0 + binSize * (double) index; + high = low + binSize; + } +} diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.h b/isis/src/base/objs/ImageHistogram/ImageHistogram.h new file mode 100644 index 0000000000..2fb5c06032 --- /dev/null +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.h @@ -0,0 +1,87 @@ +/** + * @file + * $Revision: 1.3 $ + * $Date: 2008/08/15 22:03:32 $ + * + * Unless noted otherwise, the portions of Isis written by the USGS are + * public domain. See individual third-party library and package descriptions + * for intellectual property information, user agreements, and related + * information. + * + * Although Isis has been used by the USGS, no warranty, expressed or + * implied, is made by the USGS as to the accuracy and functioning of such + * software and related material nor shall the fact of distribution + * constitute any such warranty, and no responsibility is assumed by the + * USGS in connection therewith. + * + * For additional information, launch + * $ISISROOT/doc//documents/Disclaimers/Disclaimers.html + * in a browser or see the Privacy & Disclaimers page on the Isis website, + * http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on + * http://www.usgs.gov/privacy.html. + */ +#ifndef ImageHistogram_h +#define ImageHistogram_h + +#include "Cube.h" +#include "Message.h" +#include "IException.h" +#include "Progress.h" +#include "Histogram.h" +#include "ImageHistogram.h" + +namespace Isis { + class ControlNet; + class ControlMeasure; + /** + * @brief Container of a cube histogram + * + * This class is used to accumulate a histogram on double arrays. In + * particular, it is highly useful for obtaining a histogram on cube data. + * Parameters which can be computed are the 1) median, 2) mode, and 3) skew. + * The histogram consists of a fixed set of distinct bins. When an object is + * created the programmer must provide a minimum and maximum which defines how + * data is further placed in the bins. The minimum is mapped to the left edge + * of the first bin [0] and the maximum is mapped to the right edge of the + * last bin [Bins()-1]. There are a set of methods which return bin information + * such as 1) count, 2) size, 3) middle value, 4) range, and 5) maximum bin + * count. + * + * @ingroup Statistics + * + * @author 2002-05-13 Jeff Anderson + * + * @internal + * @todo This class needs an example. + * @history 2002-05-22 Jeff Anderson moved Reset, AddData, and RemoveData + * methods into public space. + */ + + class ImageHistogram : public Histogram{ + public: + ImageHistogram(double minimum, double maximum, + int bins = 1024); + ImageHistogram(Cube &cube, int statsBand, Progress *progress = NULL, + double startSample = 1.0, double startLine = 1.0, + double endSample = Null, double endLine = Null, int bins = 0, + bool addCubeData = false); + + //constuctors that use ControlNetworks to build histograms of ControlMeasure data + ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, int bins); + ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, double binWidth); + + ~ImageHistogram(); + + void AddData(const double *data, const unsigned int count); + void AddData(const double data); + void RemoveData(const double *data, const unsigned int count); + + void BinRange(const int index, double &low, double &high) const; + + private: + //! The array of counts. + std::vector p_bins; + }; +}; + +#endif diff --git a/isis/src/base/objs/ImageHistogram/Makefile b/isis/src/base/objs/ImageHistogram/Makefile new file mode 100644 index 0000000000..f122bc8822 --- /dev/null +++ b/isis/src/base/objs/ImageHistogram/Makefile @@ -0,0 +1,7 @@ +ifeq ($(ISISROOT), $(BLANK)) +.SILENT: +error: + echo "Please set ISISROOT"; +else + include $(ISISROOT)/make/isismake.objs +endif \ No newline at end of file From e791fa5d802e82053673daac6df5fcc683ef7fa3 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 16 Sep 2020 12:36:14 -0700 Subject: [PATCH 07/16] Made shared variable protected so subclass can access it --- isis/src/base/objs/Histogram/Histogram.h | 7 ++++--- isis/src/base/objs/ImageHistogram/ImageHistogram.h | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index 430a82169d..58e527718d 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -131,7 +131,10 @@ namespace Isis { //void SetBinRange(double binStart, double binEnd); void SetValidRange(const double minimum = Isis::ValidMinimum, const double maximum = Isis::ValidMaximum); - + protected: + //! The array of counts. + std::vector p_bins; + private: void InitializeFromCube(Cube &cube, int statsBand, Progress *progress, int nbins = 0, double startSample = Null, double startLine = Null, @@ -140,8 +143,6 @@ namespace Isis { void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); - //! The array of counts. - std::vector p_bins; double p_binRangeStart, p_binRangeEnd; }; }; diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.h b/isis/src/base/objs/ImageHistogram/ImageHistogram.h index 2fb5c06032..bfe6f16a69 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.h +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.h @@ -77,10 +77,6 @@ namespace Isis { void RemoveData(const double *data, const unsigned int count); void BinRange(const int index, double &low, double &high) const; - - private: - //! The array of counts. - std::vector p_bins; }; }; From 5897759edd05d5d4630918dd8962986308eb7778 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 16 Sep 2020 13:50:28 -0700 Subject: [PATCH 08/16] Used virtual functions and reverted Cube::histogram to return a Historgram --- isis/src/base/apps/bit2bit/main.cpp | 6 +++--- isis/src/base/apps/gaussstretch/main.cpp | 2 +- isis/src/base/apps/histeq/main.cpp | 6 +++--- isis/src/base/apps/histmatch/main.cpp | 6 +++--- isis/src/base/apps/isis2raw/main.cpp | 4 ++-- isis/src/base/apps/isis2raw/tsts/8bit/Makefile | 2 +- isis/src/base/apps/percent/main.cpp | 4 ++-- isis/src/base/apps/rgb2hsv/main.cpp | 8 ++++---- isis/src/base/apps/stats/stats.cpp | 4 ++-- isis/src/base/apps/stretch/main.cpp | 3 ++- isis/src/base/objs/Cube/Cube.cpp | 6 +++--- isis/src/base/objs/Cube/Cube.h | 6 +++--- isis/src/base/objs/Cube/unitTest.cpp | 6 +++--- isis/src/base/objs/GaussianStretch/GaussianStretch.h | 2 +- isis/src/base/objs/Histogram/Histogram.cpp | 1 + isis/src/base/objs/Histogram/Histogram.h | 10 +++++----- isis/src/base/objs/ImageHistogram/ImageHistogram.cpp | 4 ++++ isis/src/base/objs/ImageHistogram/ImageHistogram.h | 8 ++++---- isis/src/base/objs/ProcessExport/ProcessExport.cpp | 4 ++-- isis/src/base/objs/Stretch/Stretch.cpp | 4 ++-- isis/src/base/objs/Stretch/Stretch.h | 4 ++-- isis/src/base/objs/Stretch/unitTest.cpp | 2 +- isis/tests/Mocks.h | 2 +- isis/tests/statsTests.cpp | 2 +- 24 files changed, 56 insertions(+), 50 deletions(-) diff --git a/isis/src/base/apps/bit2bit/main.cpp b/isis/src/base/apps/bit2bit/main.cpp index b0a9e8e6f6..bd2bdd8e8b 100644 --- a/isis/src/base/apps/bit2bit/main.cpp +++ b/isis/src/base/apps/bit2bit/main.cpp @@ -1,7 +1,7 @@ #include "Isis.h" #include "ProcessByLine.h" #include "SpecialPixel.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "UserInterface.h" #include "Pvl.h" #include "Cube.h" @@ -29,7 +29,7 @@ void IsisMain(){ A histogram is made from the input cube, as the default min of the bit2bit output is at .5% of the data range, and the default max is at 99.5% */ - ImageHistogram* histptr = cubeptr -> histogram(); + Histogram* histptr = cubeptr -> histogram(); double maxper = histptr -> Percent(ui.GetDouble("MAXPER")); double minper = histptr -> Percent(ui.GetDouble("MINPER")); @@ -70,7 +70,7 @@ void IsisMain(){ p.StartProcess(populate); - ImageHistogram* ohistptr = (ocubeptr -> histogram(1,validMin,validMax)); + Histogram* ohistptr = (ocubeptr -> histogram(1,validMin,validMax)); int iLrs = histptr -> LrsPixels(); int iHrs = histptr -> HrsPixels(); int iNull = histptr -> NullPixels(); diff --git a/isis/src/base/apps/gaussstretch/main.cpp b/isis/src/base/apps/gaussstretch/main.cpp index 321b0bb913..e826f82496 100644 --- a/isis/src/base/apps/gaussstretch/main.cpp +++ b/isis/src/base/apps/gaussstretch/main.cpp @@ -17,7 +17,7 @@ void IsisMain() { double gsigma = Isis::Application::GetUserInterface().GetDouble("GSIGMA"); for(int i = 0; i < icube->bandCount(); i++) { - ImageHistogram hist = *(icube->histogram(i + 1)); + 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)); diff --git a/isis/src/base/apps/histeq/main.cpp b/isis/src/base/apps/histeq/main.cpp index c61f1c0876..896c6cdc28 100644 --- a/isis/src/base/apps/histeq/main.cpp +++ b/isis/src/base/apps/histeq/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "Statistics.h" #include "Stretch.h" -#include "ImageHistogram.h" +#include "Histogram.h" using namespace std; using namespace Isis; @@ -25,8 +25,8 @@ void IsisMain() { int increment = ui.GetInteger("INCREMENT"); // Histograms from input cubes - ImageHistogram *from = icube->histogram(); - ImageHistogram *match = icube->histogram(); + Histogram *from = icube->histogram(); + Histogram *match = icube->histogram(); double fromMin = from->Percent(minimum); double fromMax = from->Percent(maximum); diff --git a/isis/src/base/apps/histmatch/main.cpp b/isis/src/base/apps/histmatch/main.cpp index c4147d1639..66e1978bd7 100644 --- a/isis/src/base/apps/histmatch/main.cpp +++ b/isis/src/base/apps/histmatch/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "Statistics.h" #include "Stretch.h" -#include "ImageHistogram.h" +#include "Histogram.h" using namespace std; using namespace Isis; @@ -16,10 +16,10 @@ void IsisMain() { // Setup the input and output cubes along with histograms ProcessByLine p; Cube *mcube = p.SetInputCube("MATCH", Isis::OneBand); - ImageHistogram *match = mcube->histogram(); + Histogram *match = mcube->histogram(); p.ClearInputCubes(); Cube *icube = p.SetInputCube("FROM", Isis::OneBand); - ImageHistogram *from = icube->histogram(); + Histogram *from = icube->histogram(); p.SetOutputCube("TO"); // Histogram specifications diff --git a/isis/src/base/apps/isis2raw/main.cpp b/isis/src/base/apps/isis2raw/main.cpp index 01c2ef81c5..06ac54df0e 100644 --- a/isis/src/base/apps/isis2raw/main.cpp +++ b/isis/src/base/apps/isis2raw/main.cpp @@ -6,7 +6,7 @@ #include #include -#include "ImageHistogram.h" +#include "Histogram.h" #include "ProcessExport.h" #include "UserInterface.h" #include "SpecialPixel.h" @@ -119,7 +119,7 @@ void IsisMain() { // Validates provided range void checkRange(UserInterface &ui, double &min, double &max) { - Isis::ImageHistogram *hist = p_cube->histogram(0); + Isis::Histogram *hist = p_cube->histogram(0); if(ui.WasEntered("OMIN")) { if(ui.GetDouble("OMIN") < min) { diff --git a/isis/src/base/apps/isis2raw/tsts/8bit/Makefile b/isis/src/base/apps/isis2raw/tsts/8bit/Makefile index 5ce055a926..c345f67c57 100644 --- a/isis/src/base/apps/isis2raw/tsts/8bit/Makefile +++ b/isis/src/base/apps/isis2raw/tsts/8bit/Makefile @@ -5,7 +5,7 @@ include $(ISISROOT)/make/isismake.tsts commands: $(APPNAME) from=$(INPUT)/isisTruth.cub+2 \ to=$(OUTPUT)/isis2rawTruth4.raw \ - bittype= 8BIT > /dev/null; + bittype= 8BIT; $(APPNAME) from=$(INPUT)/isisTruth.cub+2 \ to=$(OUTPUT)/isis2rawTruth4NoNull.raw \ null=no \ diff --git a/isis/src/base/apps/percent/main.cpp b/isis/src/base/apps/percent/main.cpp index 278f41c5b7..378c2713b4 100644 --- a/isis/src/base/apps/percent/main.cpp +++ b/isis/src/base/apps/percent/main.cpp @@ -6,7 +6,7 @@ #include "Process.h" #include "Pvl.h" #include "PvlFormat.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "IString.h" @@ -32,7 +32,7 @@ void IsisMain() { for(int i = 0; i < tokens.size(); i++) { double percentage = toDouble(tokens[i]); // Obtain the Histogram and the value at the percentage - ImageHistogram *hist = icube->histogram(); + Histogram *hist = icube->histogram(); double value = hist->Percent(percentage); kwPercent += toString(percentage); kwValue += toString(value); diff --git a/isis/src/base/apps/rgb2hsv/main.cpp b/isis/src/base/apps/rgb2hsv/main.cpp index 07d07c2994..c2b3c45316 100644 --- a/isis/src/base/apps/rgb2hsv/main.cpp +++ b/isis/src/base/apps/rgb2hsv/main.cpp @@ -3,7 +3,7 @@ #include "SpecialPixel.h" #include "QColor" -#include "ImageHistogram.h" +#include "Histogram.h" #include "Stretch.h" using namespace std; @@ -34,9 +34,9 @@ void IsisMain() { // Automatic is selected if(ui.GetString("MODE") == "AUTOMATIC") { - ImageHistogram *redHist = redCube->histogram(); - ImageHistogram *greenHist = greenCube->histogram(); - ImageHistogram *blueHist = blueCube->histogram(); + Histogram *redHist = redCube->histogram(); + Histogram *greenHist = greenCube->histogram(); + Histogram *blueHist = blueCube->histogram(); rMin = redHist->Percent(ui.GetDouble("RMINPER")); rMax = redHist->Percent(ui.GetDouble("RMAXPER")); diff --git a/isis/src/base/apps/stats/stats.cpp b/isis/src/base/apps/stats/stats.cpp index 7841f03025..d192551a25 100644 --- a/isis/src/base/apps/stats/stats.cpp +++ b/isis/src/base/apps/stats/stats.cpp @@ -7,7 +7,7 @@ #include "CubeAttribute.h" #include "Cube.h" #include "FileName.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "Pvl.h" #include "UserInterface.h" @@ -116,7 +116,7 @@ namespace Isis { int bandCount = cube->bandCount(); for (int i = 1; i <= bandCount; i++) { - ImageHistogram *stats = cube->histogram(i, validMin, validMax); + Histogram *stats = cube->histogram(i, validMin, validMax); // Construct a label with the results PvlGroup results("Results"); diff --git a/isis/src/base/apps/stretch/main.cpp b/isis/src/base/apps/stretch/main.cpp index 564d5680e5..37dcf08b52 100644 --- a/isis/src/base/apps/stretch/main.cpp +++ b/isis/src/base/apps/stretch/main.cpp @@ -42,8 +42,9 @@ void IsisMain() { pairs = ui.GetString("PAIRS"); } - if(ui.GetBoolean("USEPERCENTAGES")) + if(ui.GetBoolean("USEPERCENTAGES")) { str.Parse(pairs, inCube->histogram()); + } else str.Parse(pairs); diff --git a/isis/src/base/objs/Cube/Cube.cpp b/isis/src/base/objs/Cube/Cube.cpp index 8ee1366454..723cb677e8 100644 --- a/isis/src/base/objs/Cube/Cube.cpp +++ b/isis/src/base/objs/Cube/Cube.cpp @@ -1381,7 +1381,7 @@ namespace Isis { * @throws IsisProgrammerError Band was less than zero or more than the number * of bands in the cube. */ - ImageHistogram *Cube::histogram(const int &band, QString msg) { + Histogram *Cube::histogram(const int &band, QString msg) { return histogram(band, ValidMinimum, ValidMaximum, msg); } @@ -1411,7 +1411,7 @@ namespace Isis { * @throws ProgrammerError Band was less than zero or more than the number * of bands in the cube. */ - ImageHistogram *Cube::histogram(const int &band, const double &validMin, + Histogram *Cube::histogram(const int &band, const double &validMin, const double &validMax, QString msg) { // Make sure cube is open if ( !isOpen() ) { @@ -1435,7 +1435,7 @@ namespace Isis { } Progress progress; - ImageHistogram *hist = new ImageHistogram(*this, band, &progress); + Histogram *hist = new ImageHistogram(*this, band, &progress); LineManager line(*this); // This range is for throwing out data; the default parameters are OK always diff --git a/isis/src/base/objs/Cube/Cube.h b/isis/src/base/objs/Cube/Cube.h index d14d72040c..3bd4fa0494 100644 --- a/isis/src/base/objs/Cube/Cube.h +++ b/isis/src/base/objs/Cube/Cube.h @@ -49,7 +49,7 @@ namespace Isis { class Pvl; class PvlGroup; class Statistics; - class ImageHistogram; + class Histogram; /** * @brief IO Handler for Isis Cubes. @@ -284,9 +284,9 @@ namespace Isis { FileName externalCubeFileName() const; virtual QString fileName() const; Format format() const; - virtual ImageHistogram *histogram(const int &band = 1, + virtual Histogram *histogram(const int &band = 1, QString msg = "Gathering histogram"); - virtual ImageHistogram *histogram(const int &band, const double &validMin, + virtual Histogram *histogram(const int &band, const double &validMin, const double &validMax, QString msg = "Gathering histogram"); Pvl *label() const; diff --git a/isis/src/base/objs/Cube/unitTest.cpp b/isis/src/base/objs/Cube/unitTest.cpp index 6cbff8c575..e64734ca63 100644 --- a/isis/src/base/objs/Cube/unitTest.cpp +++ b/isis/src/base/objs/Cube/unitTest.cpp @@ -11,7 +11,7 @@ #include "LineManager.h" #include "Pvl.h" #include "Preference.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "SpecialPixel.h" #include "Statistics.h" @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) { // Test Histogram object on a single band, 1 by default cerr << "Testing histogram method, band 1 ... " << endl; - ImageHistogram *bandOneHist = in.histogram(); + Histogram *bandOneHist = in.histogram(); cerr << "Average: " << bandOneHist->Average() << endl; cerr << "Standard Dev: " << bandOneHist->StandardDeviation() << endl; cerr << "Mode: " << bandOneHist->Mode() << endl; @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) { // Test histogram object on all bands cerr << "Testing histogram method, all bands ... " << endl; - ImageHistogram *allBandsHistogram = in.histogram(0); + Histogram *allBandsHistogram = in.histogram(0); cerr << "Average: " << allBandsHistogram->Average() << endl; cerr << "Standard Dev: " << allBandsHistogram->StandardDeviation() << endl; cerr << "Mode: " << allBandsHistogram->Mode() << endl; diff --git a/isis/src/base/objs/GaussianStretch/GaussianStretch.h b/isis/src/base/objs/GaussianStretch/GaussianStretch.h index b114b2f2fa..1731995db8 100644 --- a/isis/src/base/objs/GaussianStretch/GaussianStretch.h +++ b/isis/src/base/objs/GaussianStretch/GaussianStretch.h @@ -25,7 +25,7 @@ #include "Statistics.h" #include "Histogram.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "Stretch.h" #include "IException.h" #include "Constants.h" diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index a1c8b096eb..566cb30140 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -633,6 +633,7 @@ namespace Isis { */ void Histogram::BinRange(const int index, double &low, double &high) const { + std::cout << "IN HISTOGRAM BINRANGE" << '\n'; if ( (index < 0) || (index >= (int)p_bins.size() ) ) { QString message = Message::ArraySubscriptNotInRange(index); diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index 58e527718d..132247e0fd 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -106,9 +106,9 @@ namespace Isis { void SetBins(const int bins); void Reset(); - void AddData(const double *data, const unsigned int count); - void AddData(const double data); - void RemoveData(const double *data, const unsigned int count); + virtual void AddData(const double *data, const unsigned int count); + virtual void AddData(const double data); + virtual void RemoveData(const double *data, const unsigned int count); double Median() const; double Mode() const; @@ -116,7 +116,7 @@ namespace Isis { double Skew() const; BigInt BinCount(const int index) const; - void BinRange(const int index, double &low, double &high) const; + virtual void BinRange(const int index, double &low, double &high) const; double BinMiddle(const int index) const; double BinSize() const; int Bins() const; @@ -134,7 +134,7 @@ namespace Isis { protected: //! The array of counts. std::vector p_bins; - + private: void InitializeFromCube(Cube &cube, int statsBand, Progress *progress, int nbins = 0, double startSample = Null, double startLine = Null, diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp index cd21cd6450..a44a6dcf33 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp @@ -122,6 +122,7 @@ namespace Isis { */ void ImageHistogram::AddData(const double *data, const unsigned int count) { + std::cout << "IN IMAGEHIST ADDDATA LIST" << '\n'; Statistics::AddData(data, count); int nbins = p_bins.size(); @@ -149,6 +150,7 @@ namespace Isis { * @param data a single observation to be added to the histogram */ void ImageHistogram::AddData(const double data) { + std::cout << "IN IMAGEHIST ADDDATA" << '\n'; Statistics::AddData(data); int nbins = p_bins.size(); @@ -178,6 +180,7 @@ namespace Isis { */ void ImageHistogram::RemoveData(const double *data, const unsigned int count) { + std::cout << "IN IMAGEHIST REMOVEDATA LIST" << '\n'; Statistics::RemoveData(data, count); int nbins = p_bins.size(); @@ -212,6 +215,7 @@ namespace Isis { */ void ImageHistogram::BinRange(const int index, double &low, double &high) const { + std::cout << "IN IMAGE HIST BINRANGE" << '\n'; if ( (index < 0) || (index >= (int)p_bins.size() ) ) { QString message = Message::ArraySubscriptNotInRange(index); diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.h b/isis/src/base/objs/ImageHistogram/ImageHistogram.h index bfe6f16a69..3f6f5bf32f 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.h +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.h @@ -72,11 +72,11 @@ namespace Isis { ~ImageHistogram(); - void AddData(const double *data, const unsigned int count); - void AddData(const double data); - void RemoveData(const double *data, const unsigned int count); + virtual void AddData(const double *data, const unsigned int count); + virtual void AddData(const double data); + virtual void RemoveData(const double *data, const unsigned int count); - void BinRange(const int index, double &low, double &high) const; + virtual void BinRange(const int index, double &low, double &high) const; }; }; diff --git a/isis/src/base/objs/ProcessExport/ProcessExport.cpp b/isis/src/base/objs/ProcessExport/ProcessExport.cpp index 85c035637b..251c06db05 100644 --- a/isis/src/base/objs/ProcessExport/ProcessExport.cpp +++ b/isis/src/base/objs/ProcessExport/ProcessExport.cpp @@ -30,7 +30,7 @@ #include "LineManager.h" #include "BandManager.h" #include "SpecialPixel.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "Stretch.h" #include "Application.h" #include "EndianSwapper.h" @@ -388,7 +388,7 @@ namespace Isis { // Or get the automatic parameters else if (strType != "NONE") { - Isis::ImageHistogram *hist = InputCubes[i]->histogram(0); + Isis::Histogram *hist = InputCubes[i]->histogram(0); p_inputMinimum.push_back(hist->Percent( Application::GetUserInterface().GetDouble("MINPERCENT"))); p_inputMaximum.push_back(hist->Percent( diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index 753c9f800f..f453a2d555 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -25,7 +25,7 @@ #include #include "Stretch.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "IString.h" #include "SpecialPixel.h" #include "IException.h" @@ -251,7 +251,7 @@ namespace Isis { * * @throws Isis::IException::User - invalid stretch pair */ - void Stretch::Parse(const QString &pairs, const Isis::ImageHistogram *hist) { + void Stretch::Parse(const QString &pairs, const Isis::Histogram *hist) { // Zero out the stretch arrays p_input.clear(); p_output.clear(); diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index ddb5b6362d..652f8d71ab 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -25,7 +25,7 @@ #include #include #include "Pvl.h" -#include "ImageHistogram.h" +#include "Histogram.h" #include "Blob.h" namespace Isis { @@ -173,7 +173,7 @@ namespace Isis { double Map(const double value) const; void Parse(const QString &pairs); - void Parse(const QString &pairs, const Isis::ImageHistogram *hist); + void Parse(const QString &pairs, const Isis::Histogram *hist); QString Text() const; diff --git a/isis/src/base/objs/Stretch/unitTest.cpp b/isis/src/base/objs/Stretch/unitTest.cpp index a73a6b039c..592c2494b0 100644 --- a/isis/src/base/objs/Stretch/unitTest.cpp +++ b/isis/src/base/objs/Stretch/unitTest.cpp @@ -6,7 +6,7 @@ #include "Stretch.h" #include "IException.h" #include "Preference.h" -#include "Histogram.h" +#include "ImageHistogram.h" using namespace Isis; using namespace std; diff --git a/isis/tests/Mocks.h b/isis/tests/Mocks.h index dda06c742c..12a3c3d48a 100644 --- a/isis/tests/Mocks.h +++ b/isis/tests/Mocks.h @@ -18,7 +18,7 @@ class MockCube : public Cube { MOCK_CONST_METHOD0(bandCount, int()); MOCK_CONST_METHOD0(fileName, QString()); MOCK_CONST_METHOD1(physicalBand, int(const int &virtualBand)); - MOCK_METHOD4(histogram, ImageHistogram*( + MOCK_METHOD4(histogram, Histogram*( const int &band, const double &validMin, const double &validMax, QString msg)); diff --git a/isis/tests/statsTests.cpp b/isis/tests/statsTests.cpp index ff027fb0f3..c5376b149b 100644 --- a/isis/tests/statsTests.cpp +++ b/isis/tests/statsTests.cpp @@ -17,7 +17,7 @@ class MockCube : public Cube { MOCK_CONST_METHOD0(bandCount, int()); MOCK_CONST_METHOD0(fileName, QString()); MOCK_CONST_METHOD1(physicalBand, int(const int &virtualBand)); - MOCK_METHOD4(histogram, ImageHistogram*( + MOCK_METHOD4(histogram, Histogram*( const int &band, const double &validMin, const double &validMax, QString msg)); From cb5b0fb7b791a0bc1102303b13c697e9205df42e Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 16 Sep 2020 13:56:35 -0700 Subject: [PATCH 09/16] Added back pipe to dev/null in makefile --- isis/src/base/apps/isis2raw/tsts/8bit/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/src/base/apps/isis2raw/tsts/8bit/Makefile b/isis/src/base/apps/isis2raw/tsts/8bit/Makefile index c345f67c57..5ce055a926 100644 --- a/isis/src/base/apps/isis2raw/tsts/8bit/Makefile +++ b/isis/src/base/apps/isis2raw/tsts/8bit/Makefile @@ -5,7 +5,7 @@ include $(ISISROOT)/make/isismake.tsts commands: $(APPNAME) from=$(INPUT)/isisTruth.cub+2 \ to=$(OUTPUT)/isis2rawTruth4.raw \ - bittype= 8BIT; + bittype= 8BIT > /dev/null; $(APPNAME) from=$(INPUT)/isisTruth.cub+2 \ to=$(OUTPUT)/isis2rawTruth4NoNull.raw \ null=no \ From a53eba6a95481b17a27303356617b76cb25effc9 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 16 Sep 2020 19:05:48 -0700 Subject: [PATCH 10/16] Fixes to some app and unit test in the hist PR --- isis/src/base/apps/gaussstretch/main.cpp | 8 ++++---- isis/src/base/objs/GaussianStretch/unitTest.cpp | 7 ++++--- isis/src/base/objs/Histogram/Histogram.cpp | 5 +---- isis/src/base/objs/ImageHistogram/ImageHistogram.cpp | 4 ---- isis/src/control/apps/cnethist/main.cpp | 3 ++- isis/src/control/apps/findfeatures/ImageSource.cpp | 3 ++- isis/src/mro/apps/hideal2pds/main.cpp | 4 ++-- isis/src/mro/apps/hirdrgen/main.cpp | 4 ++-- 8 files changed, 17 insertions(+), 21 deletions(-) diff --git a/isis/src/base/apps/gaussstretch/main.cpp b/isis/src/base/apps/gaussstretch/main.cpp index e826f82496..524a2d1620 100644 --- a/isis/src/base/apps/gaussstretch/main.cpp +++ b/isis/src/base/apps/gaussstretch/main.cpp @@ -17,10 +17,10 @@ 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); diff --git a/isis/src/base/objs/GaussianStretch/unitTest.cpp b/isis/src/base/objs/GaussianStretch/unitTest.cpp index eaec92da43..9c5d61ae91 100644 --- a/isis/src/base/objs/GaussianStretch/unitTest.cpp +++ b/isis/src/base/objs/GaussianStretch/unitTest.cpp @@ -2,6 +2,7 @@ #include #include "GaussianStretch.h" #include "Histogram.h" +#include "ImageHistogram.h" #include "IException.h" #include "Preference.h" @@ -9,7 +10,7 @@ using namespace std; int main(int argc, char *argv[]) { Isis::Preference::Preferences(true); - Isis::Histogram hist(0, 99, 100); + Isis::Histogram *hist = new Isis::ImageHistogram(0, 99, 100); cout << setprecision(14); @@ -19,8 +20,8 @@ int main(int argc, char *argv[]) { data[i] = i; } - hist.AddData(data, numData); - Isis::GaussianStretch g(hist, 49.5, 14.0); + hist->AddData(data, numData); + Isis::GaussianStretch g(*hist, 49.5, 14.0); for(int i = 0; i < numData; i++) { cout << data[i] << " " << g.Map(data[i]) << endl; } diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index 566cb30140..3315466ac8 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -203,7 +203,7 @@ namespace Isis { if (measure->IsIgnored()) continue; - this->AddData((measure->*statFunc)()); + AddData((measure->*statFunc)()); } } } @@ -633,7 +633,6 @@ namespace Isis { */ void Histogram::BinRange(const int index, double &low, double &high) const { - std::cout << "IN HISTOGRAM BINRANGE" << '\n'; if ( (index < 0) || (index >= (int)p_bins.size() ) ) { QString message = Message::ArraySubscriptNotInRange(index); @@ -664,8 +663,6 @@ namespace Isis { double low, high; BinRange(index, low, high); - printf("%f16\n", low); - printf("%f16\n", high); return (low + high) / 2.0; } diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp index a44a6dcf33..cd21cd6450 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp @@ -122,7 +122,6 @@ namespace Isis { */ void ImageHistogram::AddData(const double *data, const unsigned int count) { - std::cout << "IN IMAGEHIST ADDDATA LIST" << '\n'; Statistics::AddData(data, count); int nbins = p_bins.size(); @@ -150,7 +149,6 @@ namespace Isis { * @param data a single observation to be added to the histogram */ void ImageHistogram::AddData(const double data) { - std::cout << "IN IMAGEHIST ADDDATA" << '\n'; Statistics::AddData(data); int nbins = p_bins.size(); @@ -180,7 +178,6 @@ namespace Isis { */ void ImageHistogram::RemoveData(const double *data, const unsigned int count) { - std::cout << "IN IMAGEHIST REMOVEDATA LIST" << '\n'; Statistics::RemoveData(data, count); int nbins = p_bins.size(); @@ -215,7 +212,6 @@ namespace Isis { */ void ImageHistogram::BinRange(const int index, double &low, double &high) const { - std::cout << "IN IMAGE HIST BINRANGE" << '\n'; if ( (index < 0) || (index >= (int)p_bins.size() ) ) { QString message = Message::ArraySubscriptNotInRange(index); diff --git a/isis/src/control/apps/cnethist/main.cpp b/isis/src/control/apps/cnethist/main.cpp index 6fc5dcc15a..918d73d1a8 100644 --- a/isis/src/control/apps/cnethist/main.cpp +++ b/isis/src/control/apps/cnethist/main.cpp @@ -9,6 +9,7 @@ #include "FileList.h" #include "Process.h" #include "Histogram.h" +#include "ImageHistogram.h" #include "UserInterface.h" #include "Progress.h" #include "LineManager.h" @@ -92,7 +93,7 @@ void IsisMain() { Histogram *hist; // Setup the histogram try { - hist = new Histogram(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); + hist = new ImageHistogram(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); } catch (IException &e) { QString msg = "The following error was thrown while building a histogram from netfile [" + diff --git a/isis/src/control/apps/findfeatures/ImageSource.cpp b/isis/src/control/apps/findfeatures/ImageSource.cpp index 3c0d8e792a..a6a09dafbf 100644 --- a/isis/src/control/apps/findfeatures/ImageSource.cpp +++ b/isis/src/control/apps/findfeatures/ImageSource.cpp @@ -42,6 +42,7 @@ #include "FileName.h" #include "GenericTransform.h" #include "Histogram.h" +#include "ImageHistogram.h" #include "IException.h" #include "ImageSource.h" #include "IString.h" @@ -380,7 +381,7 @@ cv::Mat ImageSource::getGeometryMapping(ImageSource &match, } Histogram *ImageSource::getHistogram(Cube &cube) const { - QScopedPointer hist(new Histogram(cube, 1)); + QScopedPointer hist(new ImageHistogram(cube, 1)); LineManager line(cube); for(int i = 1; i <= cube.lineCount(); i++) { diff --git a/isis/src/mro/apps/hideal2pds/main.cpp b/isis/src/mro/apps/hideal2pds/main.cpp index 203f45603b..9c6627abfd 100644 --- a/isis/src/mro/apps/hideal2pds/main.cpp +++ b/isis/src/mro/apps/hideal2pds/main.cpp @@ -12,7 +12,7 @@ #include "IString.h" #include "iTime.h" #include "FileName.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "LineManager.h" #include "Longitude.h" #include "OriginalLabel.h" @@ -78,7 +78,7 @@ void IsisMain() { 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()); + ImageHistogram hist(*inputCube, band, pHist.Progress()); // Loop and accumulate histogram pHist.Progress()->SetText("Gathering Histogram"); diff --git a/isis/src/mro/apps/hirdrgen/main.cpp b/isis/src/mro/apps/hirdrgen/main.cpp index b09c45c377..655d1b2802 100644 --- a/isis/src/mro/apps/hirdrgen/main.cpp +++ b/isis/src/mro/apps/hirdrgen/main.cpp @@ -3,7 +3,7 @@ #include #include -#include "Histogram.h" +#include "ImageHistogram.h" #include "iTime.h" #include "IString.h" #include "JP2Encoder.h" @@ -61,7 +61,7 @@ void IsisMain() { 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(*icube, band, pHist.Progress()); + ImageHistogram hist(*icube, band, pHist.Progress()); // Loop and accumulate histogram pHist.Progress()->SetText("Gathering Histogram"); From bcaa8cb5a6b81c77816955862deebcf387cb40b2 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Thu, 17 Sep 2020 14:14:21 -0700 Subject: [PATCH 11/16] More test fixes --- isis/src/base/apps/hist/main.cpp | 8 +++---- isis/src/base/objs/Histogram/Histogram.cpp | 11 +--------- isis/src/base/objs/Histogram/Histogram.h | 7 ++++--- isis/src/base/objs/Histogram/unitTest.cpp | 21 ++++++++++--------- .../objs/ImageHistogram/ImageHistogram.cpp | 11 +++++++--- isis/src/lro/apps/lromakeflat/main.cpp | 3 ++- isis/src/mro/apps/hinoise/main.cpp | 5 ++--- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/isis/src/base/apps/hist/main.cpp b/isis/src/base/apps/hist/main.cpp index 6066ed630a..b14dae8743 100644 --- a/isis/src/base/apps/hist/main.cpp +++ b/isis/src/base/apps/hist/main.cpp @@ -7,6 +7,7 @@ #include "CubePlotCurve.h" #include "Histogram.h" +#include "ImageHistogram.h" #include "HistogramItem.h" #include "HistogramPlotWindow.h" #include "LineManager.h" @@ -63,10 +64,10 @@ void IsisMain() { throw IException(IException::Programmer, msg, _FILEINFO_); } } - hist = new Histogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins); + hist = new ImageHistogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins); } else { - hist = new Histogram(*icube, 1, p.Progress()); + hist = new ImageHistogram(*icube, 1, p.Progress()); if (ui.WasEntered("NBINS")){ hist->SetBins(ui.GetInteger("NBINS")); @@ -270,7 +271,7 @@ void helperButtonCalcMinMax() { line.SetLine(i); inCube.read(line); cubeStats.AddData(line.DoubleBuffer(), line.size()); - } + } inCube.close(); @@ -281,4 +282,3 @@ void helperButtonCalcMinMax() { ui.PutDouble("MAXIMUM", cubeStats.Maximum()); } - diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index 3315466ac8..77f9ce90e1 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -137,9 +137,6 @@ namespace Isis { //set the ranges rangesFromNet(net,statFunc); - - //add all the data to the now setup histogram - addMeasureDataFromNet(net,statFunc); } @@ -162,8 +159,6 @@ namespace Isis { } //get the range of the data - - rangesFromNet(net,statFunc); //Keep an eye on this to see if it breaks anything. Also, I need to create @@ -173,9 +168,6 @@ namespace Isis { double domain = this->ValidMaximum() - this->ValidMinimum(); int nBins = int ( ceil(domain/binWidth) ); SetBins(nBins); - - //add all the data to the now setup histogram - addMeasureDataFromNet(net,statFunc); } @@ -202,8 +194,7 @@ namespace Isis { const ControlMeasure *measure = point->GetMeasure(j); if (measure->IsIgnored()) continue; - - AddData((measure->*statFunc)()); + this->AddData((measure->*statFunc)()); } } } diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index 132247e0fd..dcfee4456c 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -135,14 +135,15 @@ namespace Isis { //! The array of counts. std::vector p_bins; + + void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); + void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); + private: void InitializeFromCube(Cube &cube, int statsBand, Progress *progress, int nbins = 0, double startSample = Null, double startLine = Null, double endSample = Null, double endLine = Null); - void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); - void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); - double p_binRangeStart, p_binRangeEnd; }; }; diff --git a/isis/src/base/objs/Histogram/unitTest.cpp b/isis/src/base/objs/Histogram/unitTest.cpp index 9b57169fc9..f8cbeda489 100644 --- a/isis/src/base/objs/Histogram/unitTest.cpp +++ b/isis/src/base/objs/Histogram/unitTest.cpp @@ -2,6 +2,7 @@ #include #include "QRegularExpression" #include "Histogram.h" +#include "ImageHistogram.h" #include "IException.h" #include "Preference.h" #include "LineManager.h" @@ -28,7 +29,7 @@ int main(int argc, char *argv[]) { // Old unit test begins here Isis::Preference::Preferences(true); - Isis::Histogram h(-10.0, 10.0, 21); + Isis::ImageHistogram h(-10.0, 10.0, 21); double low, high; try { @@ -88,7 +89,7 @@ int main(int argc, char *argv[]) { } try { - Isis::Histogram g(1.0, 0.0); + Isis::ImageHistogram g(1.0, 0.0); } catch(Isis::IException &e) { e.print(); @@ -168,7 +169,7 @@ int main(int argc, char *argv[]) { try { - hist1 = new Isis::Histogram(net, &Isis::ControlMeasure::GetResidualMagnitude,20); + hist1 = new Isis::ImageHistogram(net, &Isis::ControlMeasure::GetResidualMagnitude, 20); cout << endl; cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" < dCumPer) { - pdMaxDN = IString(csvArr[0]).ToDouble(); + pdMaxDN = (IString(csvArr[0]).ToDouble() + IString(csvArr[1]).ToDouble()) / 2.0; } } } - From 5f7ddf02609ff19372355a48b69632ee7e1b1f52 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Tue, 22 Sep 2020 13:05:57 -0700 Subject: [PATCH 12/16] Final updates to programs and test data for new histogram calculations --- isis/src/base/apps/hist/main.cpp | 7 +- isis/src/base/objs/Histogram/Histogram.h | 5 +- isis/src/base/objs/Histogram/Histogram.truth | 84 ++++++++++++------- isis/src/base/objs/Histogram/unitTest.cpp | 10 ++- .../objs/ImageHistogram/ImageHistogram.cpp | 4 +- isis/src/control/apps/cnethist/main.cpp | 3 +- .../control/apps/cnetwinnow/cnetwinnow.cpp | 4 +- 7 files changed, 77 insertions(+), 40 deletions(-) diff --git a/isis/src/base/apps/hist/main.cpp b/isis/src/base/apps/hist/main.cpp index b14dae8743..7b1cb81851 100644 --- a/isis/src/base/apps/hist/main.cpp +++ b/isis/src/base/apps/hist/main.cpp @@ -64,14 +64,17 @@ void IsisMain() { throw IException(IException::Programmer, msg, _FILEINFO_); } } - hist = new ImageHistogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins); + hist = new Histogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins); } else { - hist = new ImageHistogram(*icube, 1, p.Progress()); if (ui.WasEntered("NBINS")){ + hist = new Histogram(*icube, 1, p.Progress()); hist->SetBins(ui.GetInteger("NBINS")); } + else { + hist = new ImageHistogram(*icube, 1, p.Progress()); + } } // Setup the histogram diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index dcfee4456c..e68b660411 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -131,12 +131,13 @@ namespace Isis { //void SetBinRange(double binStart, double binEnd); void SetValidRange(const double minimum = Isis::ValidMinimum, const double maximum = Isis::ValidMaximum); + + void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); + protected: //! The array of counts. std::vector p_bins; - - void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); private: diff --git a/isis/src/base/objs/Histogram/Histogram.truth b/isis/src/base/objs/Histogram/Histogram.truth index 4412b086b5..9d976f0e81 100644 --- a/isis/src/base/objs/Histogram/Histogram.truth +++ b/isis/src/base/objs/Histogram/Histogram.truth @@ -585,6 +585,27 @@ Data Vector a: [ -1.79769e+308 -1.79769e+308 -1.79769e+308 -1.79769e+308 -1.79769e+308 1 2 2 3 ] +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 9 +Valid pixels: 4 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 1 +Lis pixels: 1 +His pixels: 1 +Lrs pixels: 1 +Hrs pixels: 1 +Out of range pixels: 0 +Minimum: 1 +Maximum: 3 +Valid Minimum: -10 +Valid Maximum: 10 +Sum: 8 +Sum Square: 18 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Histogram Members +++++++++++++++++++ Stats Range: (-10,10) @@ -592,23 +613,30 @@ Bin Range: (-10,10) Average: 2 Std Deviation: 0.816497 Variance: 0.666667 -Median: 0 -Mode: 0 -Skew: 7.34847 +Median: 4 +Mode: 4 +Skew: -7.34847 Percent(0.5): 0 -Percent(99.5): 5 +Percent(99.5): 4 Minimum: 1 Maximum: 3 # Bins: 5 -BinWidth: 5 +BinWidth: 4 MaxBinCount: 3 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +**********************Data Vector A Histogram********************** +Bin 0: [-10,-6], Count = 0 +Bin 1: [-6,-2], Count = 0 +Bin 2: [-2,2], Count = 1 +Bin 3: [2,6], Count = 3 +Bin 4: [6,10], Count = 0 +******************************************************************* + Data Vector b: [ -9 -7 -5 -0.5 2.3 5.5 7.1 8.2 8.3 ] - ++++++++++++++++++ Statistics Counters ++++++++++++++++++ Total pixels: 9 @@ -637,32 +665,32 @@ Bin Range: (-10,10) Average: 1.1 Std Deviation: 6.76794 Variance: 45.805 -Median: 0 -Mode: -5 -Skew: 0.487593 -Percent(0.5): -10 -Percent(99.5): 10 +Median: 4 +Mode: 8 +Skew: -1.28547 +Percent(0.5): -8 +Percent(99.5): 8 Minimum: -9 Maximum: 8.3 # Bins: 5 -BinWidth: 5 -MaxBinCount: 2 +BinWidth: 4 +MaxBinCount: 3 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ **********************Data Vector B Histogram********************** -Bin 0: [-12.5,-7.5], Count = 1 -Bin 1: [-7.5,-2.5], Count = 2 -Bin 2: [-2.5,2.5], Count = 2 -Bin 3: [2.5,7.5], Count = 2 -Bin 4: [7.5,12.5], Count = 2 +Bin 0: [-10,-6], Count = 2 +Bin 1: [-6,-2], Count = 1 +Bin 2: [-2,2], Count = 1 +Bin 3: [2,6], Count = 2 +Bin 4: [6,10], Count = 3 ******************************************************************* Removing: -9,-7,-5 **********************Data Vector B Histogram********************** -Bin 0: [-12.5,-7.5], Count = 0 -Bin 1: [-7.5,-2.5], Count = 0 -Bin 2: [-2.5,2.5], Count = 2 -Bin 3: [2.5,7.5], Count = 2 -Bin 4: [7.5,12.5], Count = 2 +Bin 0: [-10,-6], Count = 0 +Bin 1: [-6,-2], Count = 0 +Bin 2: [-2,2], Count = 1 +Bin 3: [2,6], Count = 2 +Bin 4: [6,10], Count = 3 ******************************************************************* +++++++++++++++++++ Histogram Members +++++++++++++++++++ @@ -672,11 +700,11 @@ Bin Range: (-10,10) Average: 5.15 Std Deviation: 3.55514 Variance: 12.639 -Median: 5 -Mode: 0 -Skew: 0.126577 +Median: 4 +Mode: 8 +Skew: 0.970427 Percent(0.5): 0 -Percent(99.5): 10 +Percent(99.5): 8 Minimum: **PROGRAMMER ERROR** Minimum is invalid since you removed data. Changing BinRange for b-vector's histogram... @@ -716,7 +744,7 @@ Percent(99.5): -1.79769e+308 Minimum: -1.79769e+308 Maximum: -1.79769e+308 # Bins: 5 -BinWidth: 2.5 +BinWidth: 2 MaxBinCount: 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/isis/src/base/objs/Histogram/unitTest.cpp b/isis/src/base/objs/Histogram/unitTest.cpp index f8cbeda489..fd6d35085e 100644 --- a/isis/src/base/objs/Histogram/unitTest.cpp +++ b/isis/src/base/objs/Histogram/unitTest.cpp @@ -389,8 +389,8 @@ int main(int argc, char *argv[]) { int nbins = 5; Isis::Histogram *ahist, *bhist; - ahist = new Isis::ImageHistogram (low1,high1,nbins); - bhist = new Isis::ImageHistogram (low1,high1,nbins); + ahist = new Isis::Histogram (low1,high1,nbins); + bhist = new Isis::Histogram (low1,high1,nbins); double a[9]; a[0] = 1.0; @@ -431,13 +431,17 @@ int main(int argc, char *argv[]) { arrayDisplay(a,9); cout << endl; + statCounters(ahist); histogramMembers(ahist); + cout << "**********************Data Vector A Histogram**********************" << endl; + histDisplay(ahist); + cout << "*******************************************************************" << endl; + cout << endl; cout << "Data Vector b: " << endl; arrayDisplay(b,9); cout << endl; - cout << endl; statCounters(bhist); histogramMembers(bhist); diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp index 4ff4a0c584..ff04011f4e 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp @@ -92,7 +92,7 @@ namespace Isis { Histogram(net, statFunc, bins) { //add all the data to the now setup histogram - addMeasureDataFromNet(net,statFunc); + addMeasureDataFromNet(net, statFunc); } @@ -109,7 +109,7 @@ namespace Isis { double binWidth) : Histogram(net, statFunc, binWidth) { //add all the data to the now setup histogram - addMeasureDataFromNet(net,statFunc); + addMeasureDataFromNet(net, statFunc); } diff --git a/isis/src/control/apps/cnethist/main.cpp b/isis/src/control/apps/cnethist/main.cpp index 918d73d1a8..493e39a170 100644 --- a/isis/src/control/apps/cnethist/main.cpp +++ b/isis/src/control/apps/cnethist/main.cpp @@ -93,7 +93,8 @@ void IsisMain() { Histogram *hist; // Setup the histogram try { - hist = new ImageHistogram(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); + hist = new Histogram(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); + hist->addMeasureDataFromNet(net, &ControlMeasure::GetResidualMagnitude); } catch (IException &e) { QString msg = "The following error was thrown while building a histogram from netfile [" + diff --git a/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp b/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp index cec80c1f6c..9c997ce91d 100644 --- a/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp +++ b/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp @@ -17,7 +17,7 @@ #include "ControlMeasure.h" #include "ControlPoint.h" #include "PvlGroup.h" -#include "Histogram.h" +#include "ImageHistogram.h" #include "IException.h" #include "IString.h" #include "Progress.h" @@ -90,7 +90,7 @@ namespace Isis { } } //build a Histogram of the residual Magnitudes from the ControlNet - Histogram hist(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); + ImageHistogram hist(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); //make sure there was some residual data in the control network if (hist.ValidPixels() < 1) { From 81a880d8df8f194fb22b6c45bd0ccd5e5157f785 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 23 Sep 2020 14:58:50 -0700 Subject: [PATCH 13/16] Split the rolls of imagehistogram and histogram --- isis/src/base/apps/hist/main.cpp | 3 +- isis/src/base/apps/hist/tsts/default/Makefile | 5 + isis/src/base/objs/Histogram/Histogram.cpp | 192 +--------- isis/src/base/objs/Histogram/Histogram.h | 11 +- isis/src/base/objs/Histogram/Histogram.truth | 360 ------------------ isis/src/base/objs/Histogram/unitTest.cpp | 180 +-------- .../objs/ImageHistogram/ImageHistogram.cpp | 182 +++++++-- .../base/objs/ImageHistogram/ImageHistogram.h | 11 +- isis/src/base/objs/Stretch/Stretch.h | 1 + isis/src/control/apps/cnethist/main.cpp | 1 - .../control/apps/cnetwinnow/cnetwinnow.cpp | 2 +- isis/src/mro/apps/hideal2pds/main.cpp | 156 ++++---- .../objs/HistogramTool/HistogramTool.cpp | 4 +- .../objs/ScatterPlotTool/ScatterPlotData.cpp | 5 +- 14 files changed, 259 insertions(+), 854 deletions(-) diff --git a/isis/src/base/apps/hist/main.cpp b/isis/src/base/apps/hist/main.cpp index 7b1cb81851..a242c2346e 100644 --- a/isis/src/base/apps/hist/main.cpp +++ b/isis/src/base/apps/hist/main.cpp @@ -69,8 +69,7 @@ void IsisMain() { else { if (ui.WasEntered("NBINS")){ - hist = new Histogram(*icube, 1, p.Progress()); - 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()); diff --git a/isis/src/base/apps/hist/tsts/default/Makefile b/isis/src/base/apps/hist/tsts/default/Makefile index 89268ffcf8..26600023b1 100644 --- a/isis/src/base/apps/hist/tsts/default/Makefile +++ b/isis/src/base/apps/hist/tsts/default/Makefile @@ -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; diff --git a/isis/src/base/objs/Histogram/Histogram.cpp b/isis/src/base/objs/Histogram/Histogram.cpp index 77f9ce90e1..65519b098c 100644 --- a/isis/src/base/objs/Histogram/Histogram.cpp +++ b/isis/src/base/objs/Histogram/Histogram.cpp @@ -22,7 +22,6 @@ */ #include "Histogram.h" -#include "Brick.h" #include "ControlMeasure.h" #include "ControlNet.h" #include "ControlPoint.h" @@ -54,69 +53,6 @@ namespace Isis { } - /** - * Constructs a histogram object using a cube. This constructor computes - * the minimum, maximum for the binning range and number of bins - * automatically. All statistics will still be collected, though data at - * either end of the histogram will be put into one bin in order to attempt to - * achieve better histogram statistics. - * - * TODO: progress needs to be a bool. - * - * @param cube The cube to used to determine min/max and bins - * @param statsBand The band number the histogram will be collected from - * @param progress The Progress object to be used to output the percent - * processed information - * @param startSample The sample to start reading cube data from - * @param startLine The line to start reading cube data from - * @param endSample The sample to stop reading cube data at (Null for nsamps) - * @param endLine The line to stop reading cube data at (Null for nlines) - * @param bins The number of histogram bins to create (0 for automatic) - * @param addCubeData True to fill the histogram with data in addition to - * initializing the binning ranges. - */ - Histogram::Histogram(Cube &cube, int statsBand, Progress *progress, - double startSample, double startLine, - double endSample, double endLine, - int bins, bool addCubeData) { - - InitializeFromCube(cube, statsBand, progress, bins, startSample, startLine, - endSample, endLine); - - if (addCubeData) { - Brick cubeDataBrick((int)(endSample - startSample + 1), - 1, 1, cube.pixelType()); - - // if band == 0, then we're gathering data for all bands. - int startBand = statsBand; - int endBand = statsBand; - - if (statsBand == 0) { - startBand = 1; - endBand = cube.bandCount(); - } - - if (progress != NULL) { - progress->SetText("Gathering histogram"); - progress->SetMaximumSteps( - (int)(endLine - startLine + 1) * (int)(endBand - startBand + 1)); - progress->CheckStatus(); - } - - for (int band = startBand; band <= endBand; band++) { - for (int line = (int)startLine; line <= endLine; line++) { - cubeDataBrick.SetBasePosition(qRound(startSample), line, band); - cube.read(cubeDataBrick); - AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size()); - if (progress != NULL) { - progress->CheckStatus(); - } - } - } - } - } - - /** * Constructs a histogram from a control netowrk * @@ -137,6 +73,8 @@ namespace Isis { //set the ranges rangesFromNet(net,statFunc); + //add all the data to the now setup histogram + addMeasureDataFromNet(net, statFunc); } @@ -166,8 +104,10 @@ namespace Isis { //from the domain of the data and the requested bin width calculate the number of bins double domain = this->ValidMaximum() - this->ValidMinimum(); - int nBins = int ( ceil(domain/binWidth) ); + int nBins = int ( ceil(domain/binWidth) ) - 1; SetBins(nBins); + //add all the data to the now setup histogram + addMeasureDataFromNet(net, statFunc); } @@ -247,128 +187,6 @@ namespace Isis { } - void Histogram::InitializeFromCube(Cube &cube, int statsBand, - Progress *progress, int nbins, double startSample, double startLine, - double endSample, double endLine) { - - // Make sure band is valid, 0 is valid (means all bands) - if ( (statsBand < 0) || (statsBand > cube.bandCount() ) ) { - string msg = "Cannot gather histogram for band [" + IString(statsBand) + - "]"; - throw IException(IException::Programmer, msg, _FILEINFO_); - } - - // We need to find the min/max DN value for our histogram bins to be the - // correct size. - double minDnValue = Null; - double maxDnValue = Null; - - if (cube.pixelType() == UnsignedByte) { - // If we can discretely store every data point, then we can use the - // possible extent of the data range as our min/max dn values. - if (nbins == 0) { - minDnValue = 0.0 * cube.multiplier() + cube.base(); - maxDnValue = 255.0 * cube.multiplier() + cube.base(); - nbins = 256; - } - } - else if (cube.pixelType() == UnsignedWord) { - if (nbins == 0) { - minDnValue = 0.0 * cube.multiplier() + cube.base(); - maxDnValue = 65535.0 * cube.multiplier() + cube.base(); - nbins = 65536; - } - } - else if (cube.pixelType() == SignedWord) { - if (nbins == 0) { - minDnValue = -32768.0 * cube.multiplier() + cube.base(); - maxDnValue = 32767.0 * cube.multiplier() + cube.base(); - nbins = 65536; - } - } - // 32-bit data covers too big of a range of values to use - // the min and max possible values to set our value range. - // So, just set the number of bins and then later we will - // compute the min and max value in the actual cube. - else if (cube.pixelType() == UnsignedInteger || - cube.pixelType() == SignedInteger || - cube.pixelType() == Real) { - if (nbins == 0) { - nbins = 65536; - } - } - else { - IString msg = "Unsupported pixel type"; - throw IException(IException::Programmer, msg, _FILEINFO_); - } - - if (startSample == Null) - startSample = 1.0; - - if (endSample == Null) - endSample = cube.sampleCount(); - - if (startLine == Null) - startLine = 1.0; - - if (endLine == Null) - endLine = cube.lineCount(); - - // If we still need our min/max DN values, find them. - if (minDnValue == Null || maxDnValue == Null) { - - Brick cubeDataBrick((int)(endSample - startSample + 1), - 1, 1, cube.pixelType() ); - Statistics stats; - - // if band == 0, then we're gathering stats for all bands. I'm really - // not sure that this is correct, a good idea or called from anywhere... - // but I don't have time to track down the use case. - int startBand = statsBand; - int endBand = statsBand; - - if (statsBand == 0) { - startBand = 1; - endBand = cube.bandCount(); - } - - if (progress != NULL) { - - progress->SetText("Computing min/max for histogram"); - progress->SetMaximumSteps( - (int)(endLine - startLine + 1) * (int)(endBand - startBand + 1) ); - progress->CheckStatus(); - } - - for (int band = startBand; band <= endBand; band++) { - for (int line = (int)startLine; line <= endLine; line++) { - - cubeDataBrick.SetBasePosition(qRound(startSample), line, band); - cube.read(cubeDataBrick); - stats.AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size()); - - if (progress != NULL) { - progress->CheckStatus(); - } - } - } - - if (stats.ValidPixels() == 0) { - minDnValue = 0.0; - maxDnValue = 1.0; - } - else { - minDnValue = stats.Minimum(); - maxDnValue = stats.Maximum(); - } - } - - // Set the bins and range - SetValidRange(minDnValue, maxDnValue); - SetBins(nbins); - } - - //! Destructs a histogram object. Histogram::~Histogram() { } diff --git a/isis/src/base/objs/Histogram/Histogram.h b/isis/src/base/objs/Histogram/Histogram.h index e68b660411..c7fbb6d4d7 100644 --- a/isis/src/base/objs/Histogram/Histogram.h +++ b/isis/src/base/objs/Histogram/Histogram.h @@ -90,6 +90,7 @@ namespace Isis { class Histogram : public Statistics { public: + Histogram() = default; Histogram(double minimum, double maximum, int bins = 1024); Histogram(Cube &cube, int statsBand, Progress *progress = NULL, @@ -132,20 +133,14 @@ namespace Isis { void SetValidRange(const double minimum = Isis::ValidMinimum, const double maximum = Isis::ValidMaximum); - void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); - protected: //! The array of counts. std::vector p_bins; - void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); - private: - void InitializeFromCube(Cube &cube, int statsBand, Progress *progress, - int nbins = 0, double startSample = Null, double startLine = Null, - double endSample = Null, double endLine = Null); - double p_binRangeStart, p_binRangeEnd; + void addMeasureDataFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); + void rangesFromNet(ControlNet &net, double(ControlMeasure::*statFunc)() const); }; }; diff --git a/isis/src/base/objs/Histogram/Histogram.truth b/isis/src/base/objs/Histogram/Histogram.truth index 9d976f0e81..76695e7416 100644 --- a/isis/src/base/objs/Histogram/Histogram.truth +++ b/isis/src/base/objs/Histogram/Histogram.truth @@ -215,366 +215,6 @@ Sum Square: 0 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Constructor3: -Histogram(icube,1) Real - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (-1e+20,1e+20) -Bin Range: (-1e+20,1e+20) -Average: 0 -Std Deviation: 3.10109e+19 -Variance: 9.61674e+38 -Median: 1.5259e+15 -Mode: 1.5259e+15 -Skew: -0.000147616 -Percent(0.5): -1e+20 -Percent(99.5): 1e+20 -Minimum: -1e+20 -Maximum: 1e+20 -# Bins: 65536 -BinWidth: 3.0518e+15 -MaxBinCount: 5292 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 15876 -Valid pixels: 7056 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 1764 -Lis pixels: 1764 -His pixels: 1764 -Lrs pixels: 1764 -Hrs pixels: 1764 -Out of range pixels: 0 -Minimum: -1e+20 -Maximum: 1e+20 -Valid Minimum: -1e+20 -Valid Maximum: 1e+20 -Sum: 0 -Sum Square: 6.78461e+42 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Resetting bin range to (70,110) - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (70,110) -Bin Range: (70,110) -Average: -1.79769e+308 -Std Deviation: -1.79769e+308 -Variance: -1.79769e+308 -Median: -1.79769e+308 -Mode: -1.79769e+308 -Skew: -1.79769e+308 -Percent(0.5): -1.79769e+308 -Percent(99.5): -1.79769e+308 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -# Bins: 65536 -BinWidth: 0.000610361 -MaxBinCount: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 0 -Valid pixels: 0 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 0 -Lis pixels: 0 -His pixels: 0 -Lrs pixels: 0 -Hrs pixels: 0 -Out of range pixels: 0 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -Valid Minimum: 70 -Valid Maximum: 110 -Sum: 0 -Sum Square: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Constructor3: -Histogram(icube,1) SignedWord - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (-1.00049e+20,1e+20) -Bin Range: (-1.00049e+20,1e+20) -Average: -1.14471e+15 -Std Deviation: 3.10107e+19 -Variance: 9.61663e+38 -Median: -1.52627e+15 -Mode: -1.52627e+15 -Skew: 3.69133e-05 -Percent(0.5): -1e+20 -Percent(99.5): 1e+20 -Minimum: -1e+20 -Maximum: 1e+20 -# Bins: 65536 -BinWidth: 3.05255e+15 -MaxBinCount: 5292 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 15876 -Valid pixels: 7056 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 1764 -Lis pixels: 1764 -His pixels: 1764 -Lrs pixels: 1764 -Hrs pixels: 1764 -Out of range pixels: 0 -Minimum: -1e+20 -Maximum: 1e+20 -Valid Minimum: -1.00049e+20 -Valid Maximum: 1e+20 -Sum: -8.07705e+18 -Sum Square: 6.78453e+42 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Resetting bin range to (70,110) - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (70,110) -Bin Range: (70,110) -Average: -1.79769e+308 -Std Deviation: -1.79769e+308 -Variance: -1.79769e+308 -Median: -1.79769e+308 -Mode: -1.79769e+308 -Skew: -1.79769e+308 -Percent(0.5): -1.79769e+308 -Percent(99.5): -1.79769e+308 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -# Bins: 65536 -BinWidth: 0.000610361 -MaxBinCount: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 0 -Valid pixels: 0 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 0 -Lis pixels: 0 -His pixels: 0 -Lrs pixels: 0 -Hrs pixels: 0 -Out of range pixels: 0 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -Valid Minimum: 70 -Valid Maximum: 110 -Sum: 0 -Sum Square: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Constructor3: -Histogram(icube,1) UnsignedWord - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (-1.00009e+20,1.0004e+20) -Bin Range: (-1.00009e+20,1.0004e+20) -Average: 3.33468e+19 -Std Deviation: 5.35272e+19 -Variance: 2.86516e+39 -Median: 1.52627e+15 -Mode: 1.52627e+15 -Skew: 1.86888 -Percent(0.5): -1e+20 -Percent(99.5): 1.0004e+20 -Minimum: -1e+20 -Maximum: 1.0004e+20 -# Bins: 65536 -BinWidth: 3.05255e+15 -MaxBinCount: 5292 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 15876 -Valid pixels: 10584 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 1764 -Lis pixels: 1764 -His pixels: 0 -Lrs pixels: 1764 -Hrs pixels: 0 -Out of range pixels: 0 -Minimum: -1e+20 -Maximum: 1.0004e+20 -Valid Minimum: -1.00009e+20 -Valid Maximum: 1.0004e+20 -Sum: 3.52943e+23 -Sum Square: 4.20915e+43 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Resetting bin range to (70,110) - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (70,110) -Bin Range: (70,110) -Average: -1.79769e+308 -Std Deviation: -1.79769e+308 -Variance: -1.79769e+308 -Median: -1.79769e+308 -Mode: -1.79769e+308 -Skew: -1.79769e+308 -Percent(0.5): -1.79769e+308 -Percent(99.5): -1.79769e+308 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -# Bins: 65536 -BinWidth: 0.000610361 -MaxBinCount: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 0 -Valid pixels: 0 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 0 -Lis pixels: 0 -His pixels: 0 -Lrs pixels: 0 -Hrs pixels: 0 -Out of range pixels: 0 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -Valid Minimum: 70 -Valid Maximum: 110 -Sum: 0 -Sum Square: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Constructor3: -Histogram(icube,1) UnsignedByte - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (-1.00791e+20,1.00791e+20) -Bin Range: (-1.00791e+20,1.00791e+20) -Average: 2.96443e+17 -Std Deviation: 3.10605e+19 -Variance: 9.64757e+38 -Median: 3.95257e+17 -Mode: 3.95257e+17 -Skew: -0.00954403 -Percent(0.5): -1e+20 -Percent(99.5): 1e+20 -Minimum: -1e+20 -Maximum: 1e+20 -# Bins: 256 -BinWidth: 7.90514e+17 -MaxBinCount: 5292 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 15876 -Valid pixels: 7056 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 5292 -Lis pixels: 0 -His pixels: 0 -Lrs pixels: 0 -Hrs pixels: 3528 -Out of range pixels: 0 -Minimum: -1e+20 -Maximum: 1e+20 -Valid Minimum: -1.00791e+20 -Valid Maximum: 1.00791e+20 -Sum: 2.0917e+21 -Sum Square: 6.80698e+42 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -Resetting bin range to (70,110) - -+++++++++++++++++++ Histogram Members +++++++++++++++++++ - -Stats Range: (70,110) -Bin Range: (70,110) -Average: -1.79769e+308 -Std Deviation: -1.79769e+308 -Variance: -1.79769e+308 -Median: -1.79769e+308 -Mode: -1.79769e+308 -Skew: -1.79769e+308 -Percent(0.5): -1.79769e+308 -Percent(99.5): -1.79769e+308 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -# Bins: 256 -BinWidth: 0.156863 -MaxBinCount: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -++++++++++++++++++ Statistics Counters ++++++++++++++++++ - -Total pixels: 0 -Valid pixels: 0 -Over Range pixels: 0 -Under Range pixels: 0 -Null pixels: 0 -Lis pixels: 0 -His pixels: 0 -Lrs pixels: 0 -Hrs pixels: 0 -Out of range pixels: 0 -Minimum: -1.79769e+308 -Maximum: -1.79769e+308 -Valid Minimum: 70 -Valid Maximum: 110 -Sum: 0 -Sum Square: 0 - -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Constructor4: diff --git a/isis/src/base/objs/Histogram/unitTest.cpp b/isis/src/base/objs/Histogram/unitTest.cpp index fd6d35085e..3bf4a88bbb 100644 --- a/isis/src/base/objs/Histogram/unitTest.cpp +++ b/isis/src/base/objs/Histogram/unitTest.cpp @@ -2,7 +2,6 @@ #include #include "QRegularExpression" #include "Histogram.h" -#include "ImageHistogram.h" #include "IException.h" #include "Preference.h" #include "LineManager.h" @@ -29,7 +28,7 @@ int main(int argc, char *argv[]) { // Old unit test begins here Isis::Preference::Preferences(true); - Isis::ImageHistogram h(-10.0, 10.0, 21); + Isis::Histogram h(-10.0, 10.0, 20); double low, high; try { @@ -60,10 +59,10 @@ int main(int argc, char *argv[]) { cout << "BinRange(0,low): " << low << endl; cout << "BinRange(0,high): " << high << endl; cout << "BinCount(0): " << h.BinCount(0) << endl; - h.BinRange(20, low, high); + h.BinRange(19, low, high); cout << "BinRange(20,low): " << low << endl; cout << "BinRange(20,high): " << high << endl; - cout << "BinCount(20): " << h.BinCount(20) << endl; + cout << "BinCount(20): " << h.BinCount(19) << endl; cout << endl; h.RemoveData(a, 3); @@ -81,7 +80,7 @@ int main(int argc, char *argv[]) { cout << "Percent(0.5): " << h.Percent(0.5) << endl; cout << "Percent(99.5): " << h.Percent(99.5) << endl; cout << "BinCount(0): " << h.BinCount(0) << endl; - cout << "BinCount(20): " << h.BinCount(20) << endl; + cout << "BinCount(20): " << h.BinCount(19) << endl; cout << endl; } catch(Isis::IException &e) { @@ -89,7 +88,7 @@ int main(int argc, char *argv[]) { } try { - Isis::ImageHistogram g(1.0, 0.0); + Isis::Histogram g(1.0, 0.0); } catch(Isis::IException &e) { e.print(); @@ -169,7 +168,7 @@ int main(int argc, char *argv[]) { try { - hist1 = new Isis::ImageHistogram(net, &Isis::ControlMeasure::GetResidualMagnitude, 20); + hist1 = new Isis::Histogram(net, &Isis::ControlMeasure::GetResidualMagnitude, 19); cout << endl; cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); - } - - histogramMembers(histcube); - statCounters(histcube); - cout << "Resetting bin range to (70,110)" << endl; - histcube ->SetValidRange(70,110); - histogramMembers(histcube); - statCounters(histcube); - delete(histcube); - cout << endl; - - } - catch (Isis::IException &e) { - - e.print(); - - } - - - try { - - Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_Signed16Bit.cub"); - Isis::Cube icube; - icube.open(cubeFile.expanded()); - Isis::Histogram *histcube; - histcube = new Isis::ImageHistogram(icube, 1); - - cout << endl; - - cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); - } - - histogramMembers(histcube); - statCounters(histcube); - cout << "Resetting bin range to (70,110)" << endl; - histcube ->SetValidRange(70,110); - histogramMembers(histcube); - statCounters(histcube); - delete(histcube); - cout << endl; - - } - catch (Isis::IException &e) { - - e.print(); - - } - - - try { - - Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_Unsigned16Bit.cub"); - Isis::Cube icube; - icube.open(cubeFile.expanded()); - Isis::Histogram *histcube; - histcube = new Isis::ImageHistogram(icube, 1); - - cout << endl; - - cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); - } - - histogramMembers(histcube); - statCounters(histcube); - cout << "Resetting bin range to (70,110)" << endl; - histcube ->SetValidRange(70,110); - histogramMembers(histcube); - statCounters(histcube); - delete(histcube); - cout << endl; - - } - catch (Isis::IException &e) { - - e.print(); - - } - - - try { - - Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_8Bit.cub"); - Isis::Cube icube; - icube.open(cubeFile.expanded()); - Isis::Histogram *histcube; - histcube = new Isis::ImageHistogram(icube, 1); - - cout << endl; - - cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); - } - - histogramMembers(histcube); - statCounters(histcube); - cout << "Resetting bin range to (70,110)" << endl; - histcube ->SetValidRange(70,110); - histogramMembers(histcube); - statCounters(histcube); - delete(histcube); - cout << endl; - - } - catch (Isis::IException &e) { - - e.print(); - - } - double low1 = -10; double high1 = 10; int nbins = 5; diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp index ff04011f4e..4c32892be1 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.cpp @@ -22,6 +22,7 @@ */ #include "ImageHistogram.h" +#include "Brick.h" #include "ControlNet.h" #include "ControlMeasure.h" @@ -71,47 +72,162 @@ namespace Isis { ImageHistogram::ImageHistogram(Cube &cube, int statsBand, Progress *progress, double startSample, double startLine, double endSample, double endLine, - int bins, bool addCubeData) : - Histogram(cube, statsBand, progress, - startSample, startLine, - endSample, endLine, - bins, addCubeData) { - } + int bins, bool addCubeData) { + InitializeFromCube(cube, statsBand, progress, bins, startSample, startLine, + endSample, endLine); + if (addCubeData) { + Brick cubeDataBrick((int)(endSample - startSample + 1), + 1, 1, cube.pixelType()); - /** - * Constructs a histogram from a control netowrk - * - * @param net: Reference to a ControlNetwork used to access all the measures. - * @param statFunc: Pointer to a ControlMeasure acessor, the returns of this - * function call will be used to build up the network. - * @param bins: The number of bins to divide the histogram into. - * @throws The number of Histogram Bins must be greater than 0. - */ - ImageHistogram::ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, int bins) : - Histogram(net, statFunc, bins) { + // if band == 0, then we're gathering data for all bands. + int startBand = statsBand; + int endBand = statsBand; + + if (statsBand == 0) { + startBand = 1; + endBand = cube.bandCount(); + } - //add all the data to the now setup histogram - addMeasureDataFromNet(net, statFunc); + if (progress != NULL) { + progress->SetText("Gathering histogram"); + progress->SetMaximumSteps( + (int)(endLine - startLine + 1) * (int)(endBand - startBand + 1)); + progress->CheckStatus(); + } + + for (int band = startBand; band <= endBand; band++) { + for (int line = (int)startLine; line <= endLine; line++) { + cubeDataBrick.SetBasePosition(qRound(startSample), line, band); + cube.read(cubeDataBrick); + AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size()); + if (progress != NULL) { + progress->CheckStatus(); + } + } + } + } } + void ImageHistogram::InitializeFromCube(Cube &cube, int statsBand, + Progress *progress, int nbins, double startSample, double startLine, + double endSample, double endLine) { + // Make sure band is valid, 0 is valid (means all bands) + if ( (statsBand < 0) || (statsBand > cube.bandCount() ) ) { + string msg = "Cannot gather histogram for band [" + IString(statsBand) + + "]"; + throw IException(IException::Programmer, msg, _FILEINFO_); + } - /** - * Constructs a histogram from a control netowrk - * - * @param Net: Reference to a ControlNetwork used to access all the measures. - * @param statFunc: Pointer to a ControlMeasure acessor, the returns of this. - * function call will be used to build up the network. - * @param binWidth: The width of histogram bins. - * @throws The width of Histogram Bins must be greater than 0. - */ - ImageHistogram::ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, - double binWidth) : Histogram(net, statFunc, binWidth) { + // We need to find the min/max DN value for our histogram bins to be the + // correct size. + double minDnValue = Null; + double maxDnValue = Null; - //add all the data to the now setup histogram - addMeasureDataFromNet(net, statFunc); - } + if (cube.pixelType() == UnsignedByte) { + // If we can discretely store every data point, then we can use the + // possible extent of the data range as our min/max dn values. + if (nbins == 0) { + minDnValue = 0.0 * cube.multiplier() + cube.base(); + maxDnValue = 255.0 * cube.multiplier() + cube.base(); + nbins = 256; + } + } + else if (cube.pixelType() == UnsignedWord) { + if (nbins == 0) { + minDnValue = 0.0 * cube.multiplier() + cube.base(); + maxDnValue = 65535.0 * cube.multiplier() + cube.base(); + nbins = 65536; + } + } + else if (cube.pixelType() == SignedWord) { + if (nbins == 0) { + minDnValue = -32768.0 * cube.multiplier() + cube.base(); + maxDnValue = 32767.0 * cube.multiplier() + cube.base(); + nbins = 65536; + } + } + // 32-bit data covers too big of a range of values to use + // the min and max possible values to set our value range. + // So, just set the number of bins and then later we will + // compute the min and max value in the actual cube. + else if (cube.pixelType() == UnsignedInteger || + cube.pixelType() == SignedInteger || + cube.pixelType() == Real) { + if (nbins == 0) { + nbins = 65536; + } + } + else { + IString msg = "Unsupported pixel type"; + throw IException(IException::Programmer, msg, _FILEINFO_); + } + + if (startSample == Null) + startSample = 1.0; + + if (endSample == Null) + endSample = cube.sampleCount(); + + if (startLine == Null) + startLine = 1.0; + + if (endLine == Null) + endLine = cube.lineCount(); + + // If we still need our min/max DN values, find them. + if (minDnValue == Null || maxDnValue == Null) { + + Brick cubeDataBrick((int)(endSample - startSample + 1), + 1, 1, cube.pixelType() ); + Statistics stats; + + // if band == 0, then we're gathering stats for all bands. I'm really + // not sure that this is correct, a good idea or called from anywhere... + // but I don't have time to track down the use case. + int startBand = statsBand; + int endBand = statsBand; + + if (statsBand == 0) { + startBand = 1; + endBand = cube.bandCount(); + } + + if (progress != NULL) { + + progress->SetText("Computing min/max for histogram"); + progress->SetMaximumSteps( + (int)(endLine - startLine + 1) * (int)(endBand - startBand + 1) ); + progress->CheckStatus(); + } + + for (int band = startBand; band <= endBand; band++) { + for (int line = (int)startLine; line <= endLine; line++) { + + cubeDataBrick.SetBasePosition(qRound(startSample), line, band); + cube.read(cubeDataBrick); + stats.AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size()); + + if (progress != NULL) { + progress->CheckStatus(); + } + } + } + if (stats.ValidPixels() == 0) { + minDnValue = 0.0; + maxDnValue = 1.0; + } + else { + minDnValue = stats.Minimum(); + maxDnValue = stats.Maximum(); + } + } + + // Set the bins and range + SetValidRange(minDnValue, maxDnValue); + SetBins(nbins); + } //! Destructs a histogram object. ImageHistogram::~ImageHistogram() { diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.h b/isis/src/base/objs/ImageHistogram/ImageHistogram.h index 3f6f5bf32f..85e3f935b7 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.h +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.h @@ -57,7 +57,7 @@ namespace Isis { * methods into public space. */ - class ImageHistogram : public Histogram{ + class ImageHistogram : public Histogram { public: ImageHistogram(double minimum, double maximum, int bins = 1024); @@ -66,10 +66,6 @@ namespace Isis { double endSample = Null, double endLine = Null, int bins = 0, bool addCubeData = false); - //constuctors that use ControlNetworks to build histograms of ControlMeasure data - ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, int bins); - ImageHistogram(ControlNet &net, double(ControlMeasure::*statFunc)() const, double binWidth); - ~ImageHistogram(); virtual void AddData(const double *data, const unsigned int count); @@ -77,6 +73,11 @@ namespace Isis { virtual void RemoveData(const double *data, const unsigned int count); virtual void BinRange(const int index, double &low, double &high) const; + + private: + void InitializeFromCube(Cube &cube, int statsBand, + Progress *progress, int nbins, double startSample, double startLine, + double endSample, double endLine); }; }; diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index 652f8d71ab..8ba116c791 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -25,6 +25,7 @@ #include #include #include "Pvl.h" +#include "ImageHistogram.h" #include "Histogram.h" #include "Blob.h" diff --git a/isis/src/control/apps/cnethist/main.cpp b/isis/src/control/apps/cnethist/main.cpp index 493e39a170..d744562816 100644 --- a/isis/src/control/apps/cnethist/main.cpp +++ b/isis/src/control/apps/cnethist/main.cpp @@ -94,7 +94,6 @@ void IsisMain() { // Setup the histogram try { hist = new Histogram(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); - hist->addMeasureDataFromNet(net, &ControlMeasure::GetResidualMagnitude); } catch (IException &e) { QString msg = "The following error was thrown while building a histogram from netfile [" + diff --git a/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp b/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp index 9c997ce91d..4ec30a67c4 100644 --- a/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp +++ b/isis/src/control/apps/cnetwinnow/cnetwinnow.cpp @@ -90,7 +90,7 @@ namespace Isis { } } //build a Histogram of the residual Magnitudes from the ControlNet - ImageHistogram hist(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); + Histogram hist(net, &ControlMeasure::GetResidualMagnitude, ui.GetDouble("BIN_WIDTH")); //make sure there was some residual data in the control network if (hist.ValidPixels() < 1) { diff --git a/isis/src/mro/apps/hideal2pds/main.cpp b/isis/src/mro/apps/hideal2pds/main.cpp index 9c6627abfd..2f25e47a42 100644 --- a/isis/src/mro/apps/hideal2pds/main.cpp +++ b/isis/src/mro/apps/hideal2pds/main.cpp @@ -37,7 +37,7 @@ void updatePdsLabelRootObject(PvlObject *isisCubeLab, Pvl &pdsLabel, UserInterface &ui, Camera *cam); void IsisMain() { // Get user interface and create a ProcessExportPds object - UserInterface &ui = Application::GetUserInterface(); + UserInterface &ui = Application::GetUserInterface(); ProcessExportPds p; Process pHist; double *band_min, *band_max; @@ -51,25 +51,25 @@ void IsisMain() { .findGroup("OriginalInstrument")["InstrumentId"][0]; if (origInstrument != "HIRISE") { QString msg = "Input cube must from a HiRISE image. The original " - "InstrumentId = [" + origInstrument + "InstrumentId = [" + origInstrument + "] is unsupported by hideal2pds."; throw IException(IException::Io, msg, _FILEINFO_); } QString instrumentId = isisCubeLab->findObject("IsisCube") .findGroup("Instrument")["InstrumentId"][0]; if (instrumentId != "IdealCamera") { - QString msg = "Input cube must be IdealCamera. InstrumentId = [" + QString msg = "Input cube must be IdealCamera. InstrumentId = [" + instrumentId + "] is unsupported by hideal2pds."; throw IException(IException::Io, msg, _FILEINFO_); } QString target = isisCubeLab->findObject("IsisCube") .findGroup("Instrument")["TargetName"][0]; if (target.toUpper() != "MARS") { - QString msg = "Input cube must from a HiRise image. The target = [" + QString msg = "Input cube must from a HiRise image. The target = [" + target + "] is unsupported by hideal2pds."; throw IException(IException::Io, msg, _FILEINFO_); } - + band_min = new double[inputCube->bandCount()]; band_max = new double[inputCube->bandCount()]; @@ -137,7 +137,7 @@ void IsisMain() { p.SetOutputLrs(LOW_REPR_SATU2); p.SetOutputHis(HIGH_INSTR_SATU2); p.SetOutputHrs(HIGH_REPR_SATU2); - break; + break; default: p.SetOutputType(UnsignedWord); @@ -167,7 +167,7 @@ void IsisMain() { QString isisLabelFile = ui.GetFileName("FROM"); // Translate the keywords from the input cube label that go in the PDS label - PvlToPvlTranslationManager cubeLab(*(inputCube->label()), + PvlToPvlTranslationManager cubeLab(*(inputCube->label()), "$ISISROOT/appdata/translations/MroHiriseIdealPdsExportCubeLabel.trn"); cubeLab.Auto(pdsLabel); @@ -178,7 +178,7 @@ void IsisMain() { PvlObject origLabelObj = origBlob.ReturnLabels(); origLabelObj.setName("OriginalLabelObject"); origLabel.addObject(origLabelObj); - PvlToPvlTranslationManager orig(origLabel, + PvlToPvlTranslationManager orig(origLabel, "$ISISROOT/appdata/translations/MroHirisePdsRdrOriginalLabel.trn"); orig.Auto(pdsLabel); @@ -194,14 +194,14 @@ void IsisMain() { updatePdsLabelRootObject(isisCubeLab, pdsLabel, ui, cam); // Export each of the spice tables and update table keywords in PDS file - // + // // *** NOTE *** // This could change the start byte/line values for the tables that have // already been set in the labels by the ExportTable call. This is not // a problem since our tables are detached. However, it could be a // problem if we decide to allow attached PDS products in the future. QString pdsTableFile = ""; - pdsTableFile = outPdsFile.baseName() + "_INSTRUMENT_POINTING_TABLE.dat"; + pdsTableFile = outPdsFile.baseName() + "_INSTRUMENT_POINTING_TABLE.dat"; Table instRotationTable = cam->instrumentRotation()->Cache("InstrumentPointing"); p.ExportTable(instRotationTable, pdsTableFile); PvlObject isisTableLab = instRotationTable.Label(); @@ -225,9 +225,9 @@ void IsisMain() { tableKeyword.setName("CK_TABLE_ORIGINAL_SIZE"); instPtTabLab += tableKeyword; - pdsTableFile = outPdsFile.baseName() + "_INSTRUMENT_POSITION_TABLE.dat"; + pdsTableFile = outPdsFile.baseName() + "_INSTRUMENT_POSITION_TABLE.dat"; Table instPositionTable = cam->instrumentPosition()->Cache("InstrumentPosition"); - p.ExportTable(instPositionTable, pdsTableFile); + p.ExportTable(instPositionTable, pdsTableFile); isisTableLab = instPositionTable.Label(); PvlObject &instPosTabLab = pdsLabel.findObject("INSTRUMENT_POSITION_TABLE"); tableKeyword = isisTableLab.findKeyword("CacheType"); @@ -243,9 +243,9 @@ void IsisMain() { tableKeyword.setName("SPK_TABLE_ORIGINAL_SIZE"); instPosTabLab += tableKeyword; - pdsTableFile = outPdsFile.baseName() + "_BODY_ROTATION_TABLE.dat"; + pdsTableFile = outPdsFile.baseName() + "_BODY_ROTATION_TABLE.dat"; Table bodyRotationTable = cam->bodyRotation()->Cache("BodyRotation"); - p.ExportTable(bodyRotationTable, pdsTableFile); + p.ExportTable(bodyRotationTable, pdsTableFile); isisTableLab = bodyRotationTable.Label(); PvlObject &bodyRotTabLab = pdsLabel.findObject("BODY_ROTATION_TABLE"); tableKeyword = isisTableLab.findKeyword("TimeDependentFrames"); @@ -265,16 +265,16 @@ void IsisMain() { tableKeyword.setName("SOLAR_LONGITUDE"); } else { - tableKeyword = PvlKeyword("SOLAR_LONGITUDE", + tableKeyword = PvlKeyword("SOLAR_LONGITUDE", toString(cam->solarLongitude().force360Domain() - .positiveEast(Angle::Degrees)), + .positiveEast(Angle::Degrees)), "DEGREES"); } bodyRotTabLab += tableKeyword; - pdsTableFile = outPdsFile.baseName() + "_SUN_POSITION_TABLE.dat"; + pdsTableFile = outPdsFile.baseName() + "_SUN_POSITION_TABLE.dat"; Table sunPositionTable = cam->sunPosition()->Cache("SunPosition"); - p.ExportTable(sunPositionTable, pdsTableFile); + p.ExportTable(sunPositionTable, pdsTableFile); isisTableLab = sunPositionTable.Label(); PvlObject &sunPosTabLab = pdsLabel.findObject("SUN_POSITION_TABLE"); tableKeyword = isisTableLab.findKeyword("CacheType"); @@ -290,7 +290,7 @@ void IsisMain() { tableKeyword.setName("SPK_TABLE_ORIGINAL_SIZE"); sunPosTabLab += tableKeyword; - // Read in the proper keyword types (Real, Enum, String, Integer, etc) for + // Read in the proper keyword types (Real, Enum, String, Integer, etc) for // each PvlKeyword so that the PDS labels have proper format PvlFormat *formatter = pdsLabel.format(); @@ -312,25 +312,25 @@ void IsisMain() { p.StartProcess(outputStream); p.EndProcess(); outputStream.close(); - + delete [] band_min; delete [] band_max; } /** - * This method uses a Histogram object to find the minimum and maximum DN - * values of the input cube. These values are used by the Process object - * to set the input range. - * - * @param inputCube Pointer to the inputCube - * + * This method uses a Histogram object to find the minimum and maximum DN + * values of the input cube. These values are used by the Process object + * to set the input range. + * + * @param inputCube Pointer to the inputCube + * * @return A pair whose first value is the minimum DN of the input cube and * second value is the maximum DN of the input cube. */ pair inputRange(Cube *inputCube) { Process histProcess; int band = 1; - Histogram hist(*inputCube, band, histProcess.Progress()); + ImageHistogram hist(*inputCube, band, histProcess.Progress()); // Loop and accumulate histogram histProcess.Progress()->SetText("Gathering Histogram to Find Input Range"); @@ -351,24 +351,24 @@ pair inputRange(Cube *inputCube) { } /** - * This method updates the values of the keywords in the IMAGE object of - * the pds label file. - * - * The DESCRIPTION keyword is added. - * - * If the input cube has an AlphaCube group that indicates a crop has - * been performed, SOURCE_LINE_SAMPLES, SOURCE_LINES, FIRST_LINE_SAMPLE, - * and FIRST_LINE keywords are added. - * - * The values for CENTER_FILTER_WAVELENGTH and BAND_WIDTH are updated. - * - * @param inputCubeLab PvlObject pointer to the input cube labels - * @param pdsLabel Pvl of the output PDS labels + * This method updates the values of the keywords in the IMAGE object of + * the pds label file. + * + * The DESCRIPTION keyword is added. + * + * If the input cube has an AlphaCube group that indicates a crop has + * been performed, SOURCE_LINE_SAMPLES, SOURCE_LINES, FIRST_LINE_SAMPLE, + * and FIRST_LINE keywords are added. + * + * The values for CENTER_FILTER_WAVELENGTH and BAND_WIDTH are updated. + * + * @param inputCubeLab PvlObject pointer to the input cube labels + * @param pdsLabel Pvl of the output PDS labels */ void updatePdsLabelImageObject(PvlObject *isisCubeLab, Pvl &pdsLabel) { // Add the image description to the IMAGE object in the label of the PDS product PvlObject &image = pdsLabel.findObject("IMAGE"); - image += PvlKeyword("DESCRIPTION", + image += PvlKeyword("DESCRIPTION", "HiRISE mosaicked product, not map projected"); // Add AlphaCube values to the IMAGE object @@ -446,31 +446,31 @@ void updatePdsLabelImageObject(PvlObject *isisCubeLab, Pvl &pdsLabel) { /** - * This method updates the values of the keywords in the ROOT object of - * the pds label file. - * - * The RATIONALE_DESC keyword is updated if the user entered this - * parameter. - * - * The PRODUCT_VERSION_ID is added based on the user entered parameter. - * - * The NOT_APPLICABLE_CONSTANT keyword is added. - * - * The SOFTWARE_NAME keyword is determined and added. - * - * The SHAPE_MODEL keyword from the Kernels group of the input cube is - * added with the path removed. - * - * The NaifKeywords values are added if the Object exists in the input - * cube. Otherwise, the corresponding values are calculated and added - * to the pds labels. These values are added: BODY_FRAME_CODE, - * IDEAL_FOCAL_LENGTH, IDEAL_PIXEL_PITCH, IDEAL_TRANSX, IDEAL_TRANSY, + * This method updates the values of the keywords in the ROOT object of + * the pds label file. + * + * The RATIONALE_DESC keyword is updated if the user entered this + * parameter. + * + * The PRODUCT_VERSION_ID is added based on the user entered parameter. + * + * The NOT_APPLICABLE_CONSTANT keyword is added. + * + * The SOFTWARE_NAME keyword is determined and added. + * + * The SHAPE_MODEL keyword from the Kernels group of the input cube is + * added with the path removed. + * + * The NaifKeywords values are added if the Object exists in the input + * cube. Otherwise, the corresponding values are calculated and added + * to the pds labels. These values are added: BODY_FRAME_CODE, + * IDEAL_FOCAL_LENGTH, IDEAL_PIXEL_PITCH, IDEAL_TRANSX, IDEAL_TRANSY, * IDEAL_TRANSS, and IDEAL_TRANSL. The BODY_RADII keyword is split into - * A_AXIS_RADIUS, B_AXIS_RADIUS, and C_AXIS_RADIUS - * - * @param inputCubeLab PvlObject pointer to the input cube labels - * @param pdsLabel Pvl of the output PDS labels - * @param ui UserInterface reference, so that the user entered + * A_AXIS_RADIUS, B_AXIS_RADIUS, and C_AXIS_RADIUS + * + * @param inputCubeLab PvlObject pointer to the input cube labels + * @param pdsLabel Pvl of the output PDS labels + * @param ui UserInterface reference, so that the user entered * RATIONALE_DESC and PRODUCT_VERSION_ID parameters can be * read in. * @param cam Pointer to the Camera object created from the input cube. @@ -480,13 +480,13 @@ void updatePdsLabelRootObject(PvlObject *isisCubeLab, Pvl &pdsLabel, // Replace INSTRUMENT_ID value in the output labels PvlKeyword instId("INSTRUMENT_ID", "HIRISE_IDEAL_CAMERA"); pdsLabel.addKeyword(instId, PvlContainer::Replace); - + // Add user-entered keywords to ROOT object in the label of the PDS product if(ui.WasEntered("RATIONALE_DESC")) { PvlKeyword rationale("RATIONALE_DESC", ui.GetAsString("RATIONALE_DESC")); pdsLabel.addKeyword(rationale, PvlContainer::Replace); } - else if ( !pdsLabel.hasKeyword("RATIONALE_DESC") + else if ( !pdsLabel.hasKeyword("RATIONALE_DESC") || QString(pdsLabel["RATIONALE_DESC"]) == "NULL" ){ QString msg = "Unable to export HiRise product to PDS without " "RationaleDescription value. The input cube value for this " @@ -515,11 +515,11 @@ void updatePdsLabelRootObject(PvlObject *isisCubeLab, Pvl &pdsLabel, .hasKeyword("ImageJitterCorrected")) { jitter = toInt(isisCubeLab->findObject("IsisCube") .findGroup("Instrument")["ImageJitterCorrected"][0]); - pdsLabel += PvlKeyword("IMAGE_JITTER_CORRECTED", toString((int)jitter)); + pdsLabel += PvlKeyword("IMAGE_JITTER_CORRECTED", toString((int)jitter)); } else { pdsLabel += PvlKeyword("IMAGE_JITTER_CORRECTED", "UNK"); - } + } // Add Isis Kernels group keywords to the ROOT object QString shapeModel = isisCubeLab->findObject("IsisCube").findGroup("Kernels") @@ -527,9 +527,9 @@ void updatePdsLabelRootObject(PvlObject *isisCubeLab, Pvl &pdsLabel, FileName shapeModelFileNoPath(shapeModel); pdsLabel += PvlKeyword("SHAPE_MODEL", shapeModelFileNoPath.name()); - // PRODUCT_ID and SOURCE_PRODUCT_ID should be keywords added when creating the + // PRODUCT_ID and SOURCE_PRODUCT_ID should be keywords added when creating the // mosaic input cube. - + // Add NaifKeywords Object values to the ROOT object QString radiiName = "BODY" + QString::number(cam->naifBodyCode()) + "_RADII"; PvlObject naifKeywordGroup = cam->getStoredNaifKeywords(); @@ -621,12 +621,12 @@ void updatePdsLabelRootObject(PvlObject *isisCubeLab, Pvl &pdsLabel, /** * This method updates the values of the keywords in the Time Parameters - * Group of the pds label file. - * - * The PRODUCT_CREATION_TIME keyword is determined and added to the PDS - * labels. - * - * @param pdsLabel Pvl of the output PDS labels + * Group of the pds label file. + * + * The PRODUCT_CREATION_TIME keyword is determined and added to the PDS + * labels. + * + * @param pdsLabel Pvl of the output PDS labels */ void updatePdsLabelTimeParametersGroup(Pvl &pdsLabel) { // Calculate and add PRODUCT_CREATION_TIME to the TIME_PARAMETERS group @@ -639,5 +639,3 @@ void updatePdsLabelTimeParametersGroup(Pvl &pdsLabel) { PvlGroup &timeParam = pdsLabel.findGroup("TIME_PARAMETERS"); timeParam += PvlKeyword("PRODUCT_CREATION_TIME", tmpDateTime.UTC()); } - - diff --git a/isis/src/qisis/objs/HistogramTool/HistogramTool.cpp b/isis/src/qisis/objs/HistogramTool/HistogramTool.cpp index ede924d9a4..88c4eea714 100644 --- a/isis/src/qisis/objs/HistogramTool/HistogramTool.cpp +++ b/isis/src/qisis/objs/HistogramTool/HistogramTool.cpp @@ -11,6 +11,7 @@ #include "Brick.h" #include "CubePlotCurve.h" +#include "ImageHistogram.h" #include "Histogram.h" #include "HistogramItem.h" #include "HistogramPlotWindow.h" @@ -189,7 +190,7 @@ namespace Isis { Cube *cube = activeViewport->cube(); int band = activeViewport->grayBand(); - Histogram hist(*cube, band); + ImageHistogram hist(*cube, band); //If the rubber band is a line if (rubberBandTool()->currentMode() == RubberBandTool::LineMode) { @@ -458,4 +459,3 @@ namespace Isis { } } } - diff --git a/isis/src/qisis/objs/ScatterPlotTool/ScatterPlotData.cpp b/isis/src/qisis/objs/ScatterPlotTool/ScatterPlotData.cpp index a440776c71..230d25a511 100644 --- a/isis/src/qisis/objs/ScatterPlotTool/ScatterPlotData.cpp +++ b/isis/src/qisis/objs/ScatterPlotTool/ScatterPlotData.cpp @@ -35,7 +35,7 @@ namespace Isis { int endLine = qRound(lineRange.maxValue()); ASSERT(xCube->lineCount() == yCube->lineCount()); - Histogram *xCubeHist = new Histogram(*xCube, xCubeBand, NULL, + ImageHistogram *xCubeHist = new ImageHistogram(*xCube, xCubeBand, NULL, sampleRange.minValue(), lineRange.minValue(), sampleRange.maxValue(), lineRange.maxValue(), xBinCount, true); @@ -43,7 +43,7 @@ namespace Isis { m_xCubeMax = xCubeHist->Maximum(); - Histogram *yCubeHist = new Histogram(*yCube, yCubeBand, NULL, + ImageHistogram *yCubeHist = new ImageHistogram(*yCube, yCubeBand, NULL, sampleRange.minValue(), lineRange.minValue(), sampleRange.maxValue(), lineRange.maxValue(), yBinCount, true); @@ -485,4 +485,3 @@ namespace Isis { return indices; } } - From 354552b2545bb0a385792dd870f3e187424c3377 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 23 Sep 2020 16:43:36 -0700 Subject: [PATCH 14/16] Added and updated unit test truth data --- isis/src/base/objs/Histogram/Histogram.truth | 62 +-- .../objs/ImageHistogram/ImageHistogram.truth | 360 ++++++++++++++++++ 2 files changed, 391 insertions(+), 31 deletions(-) create mode 100644 isis/src/base/objs/ImageHistogram/ImageHistogram.truth diff --git a/isis/src/base/objs/Histogram/Histogram.truth b/isis/src/base/objs/Histogram/Histogram.truth index 76695e7416..dbc834a18d 100644 --- a/isis/src/base/objs/Histogram/Histogram.truth +++ b/isis/src/base/objs/Histogram/Histogram.truth @@ -1,24 +1,24 @@ -Median: 2 -Mode: 2 -Skew: 0 -Percent(0.5): 1 -Percent(99.5): 3 -Bins: 21 +Median: 2.5 +Mode: 2.5 +Skew: -1.83712 +Percent(0.5): 1.5 +Percent(99.5): 3.5 +Bins: 20 BinSize: 1 -BinMiddle: -10 -BinRange(0,low): -10.5 -BinRange(0,high): -9.5 +BinMiddle: -9.5 +BinRange(0,low): -10 +BinRange(0,high): -9 BinCount(0): 0 -BinRange(20,low): 9.5 -BinRange(20,high): 10.5 +BinRange(20,low): 9 +BinRange(20,high): 10 BinCount(20): 0 Average: 4 -Median: 5 -Mode: 5 -Skew: -1.73205 -Percent(0.5): 2 -Percent(99.5): 5 +Median: 5.5 +Mode: 5.5 +Skew: -2.59808 +Percent(0.5): 2.5 +Percent(99.5): 5.5 BinCount(0): 0 BinCount(20): 0 @@ -49,16 +49,16 @@ Bin Range: (0.00973653,0.421463) Average: 0.128848 Std Deviation: 0.0848166 Variance: 0.00719386 -Median: 0.118086 -Mode: 0.074746 -Skew: 0.380683 -Percent(0.5): 0.00973653 -Percent(99.5): 0.421463 +Median: 0.107251 +Mode: 0.0639111 +Skew: 0.763918 +Percent(0.5): 0.0205714 +Percent(99.5): 0.410628 Minimum: 0.00973653 Maximum: 0.421463 -# Bins: 20 +# Bins: 19 BinWidth: 0.0216698 -MaxBinCount: 9 +MaxBinCount: 10 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -98,7 +98,7 @@ Percent(0.5): -1.79769e+308 Percent(99.5): -1.79769e+308 Minimum: -1.79769e+308 Maximum: -1.79769e+308 -# Bins: 20 +# Bins: 19 BinWidth: 0.00963103 MaxBinCount: 0 @@ -139,14 +139,14 @@ Bin Range: (0.00973653,0.421463) Average: 0.128848 Std Deviation: 0.0848166 Variance: 0.00719386 -Median: 0.110158 -Mode: 0.0699892 -Skew: 0.661099 -Percent(0.5): 0.00973653 -Percent(99.5): 0.421463 +Median: 0.105137 +Mode: 0.0247997 +Skew: 0.838696 +Percent(0.5): 0.0147576 +Percent(99.5): 0.416442 Minimum: 0.00973653 Maximum: 0.421463 -# Bins: 42 +# Bins: 41 BinWidth: 0.0100421 MaxBinCount: 6 @@ -188,7 +188,7 @@ Percent(0.5): -1.79769e+308 Percent(99.5): -1.79769e+308 Minimum: -1.79769e+308 Maximum: -1.79769e+308 -# Bins: 42 +# Bins: 41 BinWidth: 0.00446316 MaxBinCount: 0 diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.truth b/isis/src/base/objs/ImageHistogram/ImageHistogram.truth new file mode 100644 index 0000000000..92ea9f7c9d --- /dev/null +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.truth @@ -0,0 +1,360 @@ + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Constructor3: +Histogram(icube,1) Real + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (-1e+20,1e+20) +Bin Range: (-1e+20,1e+20) +Average: 0 +Std Deviation: 3.10109e+19 +Variance: 9.61674e+38 +Median: 1.5259e+15 +Mode: 1.5259e+15 +Skew: -0.000147616 +Percent(0.5): -1e+20 +Percent(99.5): 1e+20 +Minimum: -1e+20 +Maximum: 1e+20 +# Bins: 65536 +BinWidth: 3.0518e+15 +MaxBinCount: 5292 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 15876 +Valid pixels: 7056 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 1764 +Lis pixels: 1764 +His pixels: 1764 +Lrs pixels: 1764 +Hrs pixels: 1764 +Out of range pixels: 0 +Minimum: -1e+20 +Maximum: 1e+20 +Valid Minimum: -1e+20 +Valid Maximum: 1e+20 +Sum: 0 +Sum Square: 6.78461e+42 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Resetting bin range to (70,110) + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (70,110) +Bin Range: (70,110) +Average: -1.79769e+308 +Std Deviation: -1.79769e+308 +Variance: -1.79769e+308 +Median: -1.79769e+308 +Mode: -1.79769e+308 +Skew: -1.79769e+308 +Percent(0.5): -1.79769e+308 +Percent(99.5): -1.79769e+308 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +# Bins: 65536 +BinWidth: 0.000610361 +MaxBinCount: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 0 +Valid pixels: 0 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 0 +Lis pixels: 0 +His pixels: 0 +Lrs pixels: 0 +Hrs pixels: 0 +Out of range pixels: 0 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +Valid Minimum: 70 +Valid Maximum: 110 +Sum: 0 +Sum Square: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Constructor3: +Histogram(icube,1) SignedWord + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (-1.00049e+20,1e+20) +Bin Range: (-1.00049e+20,1e+20) +Average: -1.14471e+15 +Std Deviation: 3.10107e+19 +Variance: 9.61663e+38 +Median: -1.52627e+15 +Mode: -1.52627e+15 +Skew: 3.69133e-05 +Percent(0.5): -1e+20 +Percent(99.5): 1e+20 +Minimum: -1e+20 +Maximum: 1e+20 +# Bins: 65536 +BinWidth: 3.05255e+15 +MaxBinCount: 5292 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 15876 +Valid pixels: 7056 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 1764 +Lis pixels: 1764 +His pixels: 1764 +Lrs pixels: 1764 +Hrs pixels: 1764 +Out of range pixels: 0 +Minimum: -1e+20 +Maximum: 1e+20 +Valid Minimum: -1.00049e+20 +Valid Maximum: 1e+20 +Sum: -8.07705e+18 +Sum Square: 6.78453e+42 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Resetting bin range to (70,110) + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (70,110) +Bin Range: (70,110) +Average: -1.79769e+308 +Std Deviation: -1.79769e+308 +Variance: -1.79769e+308 +Median: -1.79769e+308 +Mode: -1.79769e+308 +Skew: -1.79769e+308 +Percent(0.5): -1.79769e+308 +Percent(99.5): -1.79769e+308 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +# Bins: 65536 +BinWidth: 0.000610361 +MaxBinCount: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 0 +Valid pixels: 0 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 0 +Lis pixels: 0 +His pixels: 0 +Lrs pixels: 0 +Hrs pixels: 0 +Out of range pixels: 0 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +Valid Minimum: 70 +Valid Maximum: 110 +Sum: 0 +Sum Square: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Constructor3: +Histogram(icube,1) UnsignedWord + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (-1.00009e+20,1.0004e+20) +Bin Range: (-1.00009e+20,1.0004e+20) +Average: 3.33468e+19 +Std Deviation: 5.35272e+19 +Variance: 2.86516e+39 +Median: 1.52627e+15 +Mode: 1.52627e+15 +Skew: 1.86888 +Percent(0.5): -1e+20 +Percent(99.5): 1.0004e+20 +Minimum: -1e+20 +Maximum: 1.0004e+20 +# Bins: 65536 +BinWidth: 3.05255e+15 +MaxBinCount: 5292 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 15876 +Valid pixels: 10584 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 1764 +Lis pixels: 1764 +His pixels: 0 +Lrs pixels: 1764 +Hrs pixels: 0 +Out of range pixels: 0 +Minimum: -1e+20 +Maximum: 1.0004e+20 +Valid Minimum: -1.00009e+20 +Valid Maximum: 1.0004e+20 +Sum: 3.52943e+23 +Sum Square: 4.20915e+43 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Resetting bin range to (70,110) + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (70,110) +Bin Range: (70,110) +Average: -1.79769e+308 +Std Deviation: -1.79769e+308 +Variance: -1.79769e+308 +Median: -1.79769e+308 +Mode: -1.79769e+308 +Skew: -1.79769e+308 +Percent(0.5): -1.79769e+308 +Percent(99.5): -1.79769e+308 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +# Bins: 65536 +BinWidth: 0.000610361 +MaxBinCount: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 0 +Valid pixels: 0 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 0 +Lis pixels: 0 +His pixels: 0 +Lrs pixels: 0 +Hrs pixels: 0 +Out of range pixels: 0 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +Valid Minimum: 70 +Valid Maximum: 110 +Sum: 0 +Sum Square: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Constructor3: +Histogram(icube,1) UnsignedByte + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (-1.00791e+20,1.00791e+20) +Bin Range: (-1.00791e+20,1.00791e+20) +Average: 2.96443e+17 +Std Deviation: 3.10605e+19 +Variance: 9.64757e+38 +Median: 3.95257e+17 +Mode: 3.95257e+17 +Skew: -0.00954403 +Percent(0.5): -1e+20 +Percent(99.5): 1e+20 +Minimum: -1e+20 +Maximum: 1e+20 +# Bins: 256 +BinWidth: 7.90514e+17 +MaxBinCount: 5292 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 15876 +Valid pixels: 7056 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 5292 +Lis pixels: 0 +His pixels: 0 +Lrs pixels: 0 +Hrs pixels: 3528 +Out of range pixels: 0 +Minimum: -1e+20 +Maximum: 1e+20 +Valid Minimum: -1.00791e+20 +Valid Maximum: 1.00791e+20 +Sum: 2.0917e+21 +Sum Square: 6.80698e+42 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Resetting bin range to (70,110) + ++++++++++++++++++++ Histogram Members +++++++++++++++++++ + +Stats Range: (70,110) +Bin Range: (70,110) +Average: -1.79769e+308 +Std Deviation: -1.79769e+308 +Variance: -1.79769e+308 +Median: -1.79769e+308 +Mode: -1.79769e+308 +Skew: -1.79769e+308 +Percent(0.5): -1.79769e+308 +Percent(99.5): -1.79769e+308 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +# Bins: 256 +BinWidth: 0.156863 +MaxBinCount: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +++++++++++++++++++ Statistics Counters ++++++++++++++++++ + +Total pixels: 0 +Valid pixels: 0 +Over Range pixels: 0 +Under Range pixels: 0 +Null pixels: 0 +Lis pixels: 0 +His pixels: 0 +Lrs pixels: 0 +Hrs pixels: 0 +Out of range pixels: 0 +Minimum: -1.79769e+308 +Maximum: -1.79769e+308 +Valid Minimum: 70 +Valid Maximum: 110 +Sum: 0 +Sum Square: 0 + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + From 75cc03b0b3ec78a8b111223c6ddaba6213349760 Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Wed, 23 Sep 2020 18:47:58 -0700 Subject: [PATCH 15/16] Added the ImageHistogram unittest file --- .../src/base/objs/ImageHistogram/unitTest.cpp | 284 ++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 isis/src/base/objs/ImageHistogram/unitTest.cpp diff --git a/isis/src/base/objs/ImageHistogram/unitTest.cpp b/isis/src/base/objs/ImageHistogram/unitTest.cpp new file mode 100644 index 0000000000..40b362e11f --- /dev/null +++ b/isis/src/base/objs/ImageHistogram/unitTest.cpp @@ -0,0 +1,284 @@ +#include +#include +#include "QRegularExpression" +#include "ImageHistogram.h" +#include "IException.h" +#include "Preference.h" +#include "LineManager.h" +#include "ControlNet.h" +#include "ControlMeasure.h" +#include "Progress.h" +#include "IException.h" +#include "FileName.h" +using namespace std; +#include +#include +#include +#include + +void arrayDisplay(double *array, int size ); +void histogramMembers(Isis::ImageHistogram *h); +void statCounters(Isis::ImageHistogram *h); +void histDisplay(Isis::ImageHistogram *h); + +int main(int argc, char *argv[]) { + try { + + Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth.cub"); + Isis::Cube icube; + icube.open(cubeFile.expanded()); + Isis::ImageHistogram *histcube; + histcube = new Isis::ImageHistogram(icube, 1); + + cout << endl; + + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); + } + + histogramMembers(histcube); + statCounters(histcube); + cout << "Resetting bin range to (70,110)" << endl; + histcube ->SetValidRange(70,110); + histogramMembers(histcube); + statCounters(histcube); + delete(histcube); + cout << endl; + + } + catch (Isis::IException &e) { + + e.print(); + + } + + + try { + + Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_Signed16Bit.cub"); + Isis::Cube icube; + icube.open(cubeFile.expanded()); + Isis::ImageHistogram *histcube; + histcube = new Isis::ImageHistogram(icube, 1); + + cout << endl; + + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); + } + + histogramMembers(histcube); + statCounters(histcube); + cout << "Resetting bin range to (70,110)" << endl; + histcube ->SetValidRange(70,110); + histogramMembers(histcube); + statCounters(histcube); + delete(histcube); + cout << endl; + + } + catch (Isis::IException &e) { + + e.print(); + + } + + + try { + + Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_Unsigned16Bit.cub"); + Isis::Cube icube; + icube.open(cubeFile.expanded()); + Isis::ImageHistogram *histcube; + histcube = new Isis::ImageHistogram(icube, 1); + + cout << endl; + + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); + } + + histogramMembers(histcube); + statCounters(histcube); + cout << "Resetting bin range to (70,110)" << endl; + histcube ->SetValidRange(70,110); + histogramMembers(histcube); + statCounters(histcube); + delete(histcube); + cout << endl; + + } + catch (Isis::IException &e) { + + e.print(); + + } + + + try { + + Isis::FileName cubeFile("$ISISTESTDATA/isis/src/base/unitTestData/isisTruth_8Bit.cub"); + Isis::Cube icube; + icube.open(cubeFile.expanded()); + Isis::ImageHistogram *histcube; + histcube = new Isis::ImageHistogram(icube, 1); + + cout << endl; + + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" <AddData(lm.DoubleBuffer(),lm.size()); + } + + histogramMembers(histcube); + statCounters(histcube); + cout << "Resetting bin range to (70,110)" << endl; + histcube ->SetValidRange(70,110); + histogramMembers(histcube); + statCounters(histcube); + delete(histcube); + cout << endl; + + } + catch (Isis::IException &e) { + + e.print(); + + } +} + +//Simple function for outputting a sorted vector + +void arrayDisplay(double *array, int size ){ + + vector v(size); + + for (int i=0; i < size; i++ ) + v[i]= array[i]; + + sort (v.begin(),v.end() ); + + cout << "[ " ; + for (std::vector::iterator it = v.begin(); it != v.end(); it++) + cout << *it << " "; + + cout << "]" << endl; + + } + +void histDisplay(Isis::ImageHistogram *h){ + + double low, high; + + for (int i = 0; i < h->Bins(); i++){ + + h->BinRange(i,low,high); + cout <<"Bin " << i << ": [" << low << "," << high << "], Count = " << h->BinCount(i) + << endl; + } + +} + + +void histogramMembers(Isis::ImageHistogram *h){ + + try{ + cout << endl; + cout << "+++++++++++++++++++ Histogram Members +++++++++++++++++++" << endl; + cout << endl; + cout << "Stats Range: (" << h->ValidMinimum() << "," << h->ValidMaximum() << ")" + << endl; + cout << "Bin Range: (" << h->BinRangeStart() <<","<< h->BinRangeEnd()<<")" + << endl; + cout << "Average: "; cout << h-> Average() << endl; + cout << "Std Deviation: "; cout << h->StandardDeviation() << endl; + cout << "Variance: "; cout << h->Variance() <Median() << endl; + cout << "Mode: "; cout << h->Mode() << endl; + cout << "Skew: "; cout << h->Skew() << endl; + cout << "Percent(0.5): "; cout << h->Percent(0.5) << endl; + cout << "Percent(99.5): "; cout << h->Percent(99.5) << endl; + cout << "Minimum: "; cout << h-> Minimum() << endl; + cout << "Maximum: "; cout << h-> Maximum() << endl; + cout << "# Bins: "; cout << h->Bins() << endl; + cout << "BinWidth: "; cout << h->BinSize() << endl; + cout << "MaxBinCount: "; cout << h->MaxBinCount() << endl; + cout << endl; + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + } + catch(Isis::IException &e){ + + e.print(); + } + + + +} + + +void statCounters(Isis::ImageHistogram *h){ + + cout << endl; + cout << "++++++++++++++++++ Statistics Counters ++++++++++++++++++" << endl; + cout << endl; + cout << "Total pixels: " << h->TotalPixels() << endl; + cout << "Valid pixels: " << h->ValidPixels() << endl; + cout << "Over Range pixels: " << h->OverRangePixels() << endl; + cout << "Under Range pixels: " << h->UnderRangePixels() << endl; + cout << "Null pixels: " << h->NullPixels() << endl; + cout << "Lis pixels: " << h->LisPixels() << endl; + cout << "His pixels: " << h->HisPixels() << endl; + cout << "Lrs pixels: " << h->LrsPixels() << endl; + cout << "Hrs pixels: " << h->HrsPixels() << endl; + cout << "Out of range pixels: " << h->OutOfRangePixels() << endl; + cout << "Minimum: " << h->Minimum() << endl; + cout << "Maximum: " << h->Maximum() << endl; + cout << "Valid Minimum: " << h->ValidMinimum() << endl; + cout << "Valid Maximum: " << h->ValidMaximum() << endl; + cout << "Sum: " << h->Sum() << endl; + cout << "Sum Square: " << h->SumSquare() << endl; + cout << endl; + cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl; + + + +} From 07b35d640263d79fc3c1d6a859690c0a284f5bef Mon Sep 17 00:00:00 2001 From: Adam Paquette Date: Thu, 24 Sep 2020 17:14:48 -0700 Subject: [PATCH 16/16] Resolved last comments on hist PR --- isis/src/base/apps/gaussstretch/main.cpp | 8 +++++++- isis/src/base/objs/GaussianStretch/GaussianStretch.h | 1 - isis/src/base/objs/ImageHistogram/ImageHistogram.h | 11 ++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/isis/src/base/apps/gaussstretch/main.cpp b/isis/src/base/apps/gaussstretch/main.cpp index 524a2d1620..801f0e605b 100644 --- a/isis/src/base/apps/gaussstretch/main.cpp +++ b/isis/src/base/apps/gaussstretch/main.cpp @@ -25,8 +25,14 @@ void IsisMain() { 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 diff --git a/isis/src/base/objs/GaussianStretch/GaussianStretch.h b/isis/src/base/objs/GaussianStretch/GaussianStretch.h index 1731995db8..d194954b90 100644 --- a/isis/src/base/objs/GaussianStretch/GaussianStretch.h +++ b/isis/src/base/objs/GaussianStretch/GaussianStretch.h @@ -25,7 +25,6 @@ #include "Statistics.h" #include "Histogram.h" -#include "Histogram.h" #include "Stretch.h" #include "IException.h" #include "Constants.h" diff --git a/isis/src/base/objs/ImageHistogram/ImageHistogram.h b/isis/src/base/objs/ImageHistogram/ImageHistogram.h index 85e3f935b7..058a6bdc98 100644 --- a/isis/src/base/objs/ImageHistogram/ImageHistogram.h +++ b/isis/src/base/objs/ImageHistogram/ImageHistogram.h @@ -36,25 +36,22 @@ namespace Isis { /** * @brief Container of a cube histogram * - * This class is used to accumulate a histogram on double arrays. In + * This class is used to accumulate an image histogram on double arrays. In * particular, it is highly useful for obtaining a histogram on cube data. * Parameters which can be computed are the 1) median, 2) mode, and 3) skew. * The histogram consists of a fixed set of distinct bins. When an object is * created the programmer must provide a minimum and maximum which defines how - * data is further placed in the bins. The minimum is mapped to the left edge - * of the first bin [0] and the maximum is mapped to the right edge of the + * data is further placed in the bins. The minimum is mapped to the middle + * of the first bin [0] and the maximum is mapped to the middle of the * last bin [Bins()-1]. There are a set of methods which return bin information * such as 1) count, 2) size, 3) middle value, 4) range, and 5) maximum bin * count. * * @ingroup Statistics * - * @author 2002-05-13 Jeff Anderson + * @author 2020-09-22 Adam Paquette * * @internal - * @todo This class needs an example. - * @history 2002-05-22 Jeff Anderson moved Reset, AddData, and RemoveData - * methods into public space. */ class ImageHistogram : public Histogram {