Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert reverted histogram PR and handle conflicts. #4004

Merged
merged 19 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ update the Unreleased link so that it compares against the latest release tag.

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

- mro/hideal2pds app now writes the correct SAMPLE_BIT_MASK values to the output label. [#3978](https://github.com/USGS-Astrogeology/ISIS3/issues/3978)

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

### Added
- A Gui Helper gear was added to hist to fill in the minimum and maximum parameters with what would have been automatically calculated. [#3880](https://github.com/USGS-Astrogeology/ISIS3/issues/3880)

- A Gui Helper gear was added to hist to fill in the minimum and maximum parameters with what would have been automatically calculated. [#3880](https://github.com/USGS-Astrogeology/ISIS3/issues/3880)

## [4.2.0] - 2020-07-27

Expand Down
40 changes: 20 additions & 20 deletions isis/src/base/apps/bit2bit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@
#include "Cube.h"
#include "Process.h"

using namespace std;
using namespace std;
using namespace Isis;

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();

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;
Expand All @@ -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));
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
Expand All @@ -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));
Expand All @@ -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
Expand All @@ -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));
Expand All @@ -141,7 +141,7 @@ void IsisMain(){
results += PvlKeyword ("OUTPUT_MIN",toString(validMin));
results += PvlKeyword ("OUTPUT_MAX",toString(validMax));
Application::Log(results);

delete histptr;
}
}
Expand Down
9 changes: 4 additions & 5 deletions isis/src/base/apps/gaussstretch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
acpaquette marked this conversation as resolved.
Show resolved Hide resolved
}

p.StartProcess(gauss);
Expand All @@ -36,4 +36,3 @@ void gauss(Buffer &in, Buffer &out) {
out[i] = stretch[in.Band(i)-1]->Map(in[i]);
}
}

6 changes: 6 additions & 0 deletions isis/src/base/apps/hist/hist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
Updated logic such that min/max values are no longer calculated from .cub
if values are provided by the user. Fixes #3881.
</change>
<change name="Kaitlyn Lee" date="2020-06-11">
Added "Pixels Below Min" and "Pixels Above Max" to the CSV output and changed how the data is
outputted. Originally, the CSV output and the GUI histogram would use the DN value in the
middle of a bin to represent that bin. That is, the CSV output used to have a "DN" value that
was the bin's middle pixel DN. This was not intuitive to users. Removed the "DN" value and added "MinInclusive" and "MaxExclusive" to the CSV so that bins are represented by their min/max values. These changes were also reflected in the histrogram creation. The x-axis is now based off of the min value of a bin instead of the middle value. These changes were made alongside changes made to Histogram and cnethist.
</change>
<change name="Kristin Berry" date="2020-06-25">
Re-added the ability to set number of bins without setting min/max values after the last update.
Follow-on to #3881.
Expand Down
101 changes: 51 additions & 50 deletions isis/src/base/apps/hist/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "CubePlotCurve.h"
#include "Histogram.h"
#include "ImageHistogram.h"
#include "HistogramItem.h"
#include "HistogramPlotWindow.h"
#include "LineManager.h"
Expand All @@ -33,7 +34,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_);
}
Expand Down Expand Up @@ -66,11 +67,14 @@ void IsisMain() {
hist = new Histogram(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"), nbins);
}
else {
hist = new Histogram(*icube, 1, p.Progress());

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

// Setup the histogram
Expand All @@ -88,46 +92,53 @@ void IsisMain() {
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 << ",";
Expand All @@ -137,10 +148,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 {
Expand All @@ -153,19 +164,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());
}
Expand All @@ -174,13 +185,16 @@ void IsisMain() {
QVector<QPointF> binCountData;
QVector<QPointF> 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) );
}
}

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

//These are all variables needed in the following for loop.
//----------------------------------------------
QVector<QwtIntervalSample> intervals(binCountData.size() );
// double maxYValue = DBL_MIN;
// double minYValue = DBL_MAX;
// // ---------------------------------------------
//
for(int y = 0; y < binCountData.size(); y++) {
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);
Expand All @@ -226,10 +232,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' +
Expand Down Expand Up @@ -272,7 +274,7 @@ void helperButtonCalcMinMax() {
line.SetLine(i);
inCube.read(line);
cubeStats.AddData(line.DoubleBuffer(), line.size());
}
}

inCube.close();

Expand All @@ -283,4 +285,3 @@ void helperButtonCalcMinMax() {
ui.PutDouble("MAXIMUM", cubeStats.Maximum());

}

Loading