49 Histogram::Histogram(
double minimum,
double maximum,
int nbins) {
51 SetValidRange(minimum, maximum);
78 Histogram::Histogram(
Cube &cube,
int statsBand,
Progress *progress,
79 double startSample,
double startLine,
80 double endSample,
double endLine,
81 int bins,
bool addCubeData) {
83 InitializeFromCube(cube, statsBand, progress, bins, startSample, startLine,
87 Brick cubeDataBrick((
int)(endSample - startSample + 1),
91 int startBand = statsBand;
92 int endBand = statsBand;
99 if (progress != NULL) {
100 progress->
SetText(
"Gathering histogram");
102 (
int)(endLine - startLine + 1) * (
int)(endBand - startBand + 1));
106 for (
int band = startBand; band <= endBand; band++) {
107 for (
int line = (
int)startLine; line <= endLine; line++) {
108 cubeDataBrick.SetBasePosition(qRound(startSample), line, band);
109 cube.
read(cubeDataBrick);
110 AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size());
111 if (progress != NULL) {
133 string msg =
"The number of Histogram Bins must be greater than 0";
139 rangesFromNet(net,statFunc);
142 addMeasureDataFromNet(net,statFunc);
159 if (binWidth <= 0 ) {
160 string msg =
"The width of Histogram Bins must be greater than 0";
167 rangesFromNet(net,statFunc);
186 int nBins = int ( ceil(domain/binWidth) );
190 addMeasureDataFromNet(net,statFunc);
206 for (
int i=0; i<nObjPts; i++) {
208 if (point->IsIgnored() )
continue;
211 int nObs = point->GetNumMeasures();
212 for (
int j=0; j<nObs; j++) {
216 if (measure->IsIgnored())
continue;
218 this->AddData((measure->*statFunc)());
239 for (
int i=0; i<nObjPts; i++) {
242 if (point->IsIgnored())
continue;
245 int nObs = point->GetNumMeasures();
247 for (
int j=0; j<nObs; j++) {
250 if (measure->IsIgnored())
continue;
252 temp = (measure->*statFunc)();
253 if (temp > max) max = temp;
254 if (temp < min) min = temp;
260 string msg =
"The net file appears to have 1 or fewer measures with residual data, "
261 "thus no histogram for this net file can be created;";
267 SetValidRange(min, max);
272 void Histogram::InitializeFromCube(
Cube &cube,
int statsBand,
273 Progress *progress,
int nbins,
double startSample,
double startLine,
274 double endSample,
double endLine) {
277 if ( (statsBand < 0) || (statsBand > cube.
bandCount() ) ) {
278 string msg =
"Cannot gather histogram for band [" +
IString(statsBand) +
285 double minDnValue =
Null;
286 double maxDnValue =
Null;
297 else if (cube.
pixelType() == UnsignedWord) {
304 else if (cube.
pixelType() == SignedWord) {
319 IString msg =
"Unsupported pixel type";
320 throw IException(IException::Programmer, msg,
_FILEINFO_);
323 if (startSample ==
Null)
326 if (endSample ==
Null)
329 if (startLine ==
Null)
336 if (minDnValue ==
Null || maxDnValue ==
Null) {
338 Brick cubeDataBrick((
int)(endSample - startSample + 1),
345 int startBand = statsBand;
346 int endBand = statsBand;
348 if (statsBand == 0) {
353 if (progress != NULL) {
355 progress->
SetText(
"Computing min/max for histogram");
357 (
int)(endLine - startLine + 1) * (
int)(endBand - startBand + 1) );
361 for (
int band = startBand; band <= endBand; band++) {
362 for (
int line = (
int)startLine; line <= endLine; line++) {
364 cubeDataBrick.SetBasePosition(qRound(startSample), line, band);
365 cube.
read(cubeDataBrick);
366 stats.AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size());
368 if (progress != NULL) {
374 if (stats.ValidPixels() == 0) {
379 minDnValue = stats.Minimum();
380 maxDnValue = stats.Maximum();
385 SetValidRange(minDnValue, maxDnValue);
391 Histogram::~Histogram() {
408 void Histogram::SetValidRange(
double binStart,
double binEnd) {
409 if (binEnd < binStart) {
410 string msg =
"The binning range start [" +
IString(binStart) +
"]"
411 " must be less than the end [" +
IString(binEnd) +
"].";
419 Isis::Statistics::SetValidRange(binStart,binEnd);
420 p_binRangeStart = binStart;
421 p_binRangeEnd = binEnd;
426 void Histogram::Reset() {
428 for (
int i = 0; i < (int)p_bins.size(); i++) {
435 void Histogram::SetBins(
const int nbins) {
436 p_bins.resize(nbins);
448 void Histogram::AddData(
const double *data,
449 const unsigned int count) {
450 Statistics::AddData(data, count);
452 int nbins = p_bins.size();
454 for (
unsigned int i = 0; i < count; i++) {
456 if (BinRangeStart() == BinRangeEnd() ) {
460 index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
461 (data[i] - BinRangeStart() ) + 0.5);
463 if (index < 0) index = 0;
464 if (index >= nbins) index = nbins - 1;
478 void Histogram::AddData(
const double data) {
479 Statistics::AddData(data);
481 int nbins = p_bins.size();
484 if (BinRangeStart() == BinRangeEnd() ) {
488 index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart() ) *
489 (data - BinRangeStart() ) + 0.5);
491 if (index < 0) index = 0;
492 if (index >= nbins) index = nbins - 1;
507 void Histogram::RemoveData(
const double *data,
508 const unsigned int count) {
509 Statistics::RemoveData(data, count);
511 int nbins = p_bins.size();
513 for (
unsigned int i = 0; i < count; i++) {
516 if (BinRangeStart() == BinRangeEnd() ) {
520 index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
521 (data[i] - BinRangeStart()) + 0.5);
523 if (index < 0) index = 0;
524 if (index >= nbins) index = nbins - 1;
535 double Histogram::Median()
const {
536 return Percent(50.0);
544 double Histogram::Mode()
const {
546 for (
int i = 0; i < (int)p_bins.size(); i++) {
548 if (p_bins[i] > p_bins[mode]) mode = i;
551 if (p_bins[mode] < 1)
return NULL8;
553 return BinMiddle(mode);
567 double Histogram::Percent(
double percent)
const {
568 if ( (percent < 0.0) || (percent > 100.0) ) {
569 string m =
"Argument percent outside of the range 0 to 100 in";
570 m +=
" [Histogram::Percent]";
574 if (ValidPixels() < 1)
return NULL8;
576 BigInt currentPixels = 0;
577 double currentPercent;
579 for (
int i = 0; i < (int)p_bins.size(); i++) {
581 currentPixels += p_bins[i];
582 currentPercent = (double) currentPixels / (
double) ValidPixels() * 100.0;
584 if (currentPercent >= percent) {
589 return BinMiddle( (
int)p_bins.size() - 1);
600 double Histogram::Skew()
const {
602 if (ValidPixels() < 1)
return NULL8;
604 double sdev = StandardDeviation();
606 if (sdev == 0.0)
return 0.0;
608 return 3.0 * (
Average() - Median()) / sdev;
619 BigInt Histogram::BinCount(
const int index)
const {
621 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
628 return p_bins[index];
643 void Histogram::BinRange(
const int index,
644 double &low,
double &high)
const {
645 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
651 double binSize = (BinRangeEnd() - BinRangeStart()) / (
double)(p_bins.size() - 1);
652 low = BinRangeStart() - binSize / 2.0 + binSize * (double) index;
653 high = low + binSize;
665 double Histogram::BinMiddle(
const int index)
const {
666 if ( (index < 0) || (index >= (
int)p_bins.size() ) ) {
674 BinRange(index, low, high);
675 return (low + high) / 2.0;
686 double Histogram::BinSize()
const {
689 BinRange(0, low, high);
699 int Histogram::Bins()
const {
700 return (
int)p_bins.size();
709 BigInt Histogram::MaxBinCount()
const {
711 BigInt maxBinCount = 0;
712 for (
int i = 0; i < (int)p_bins.size(); i++) {
713 if (p_bins[i] > maxBinCount) maxBinCount = p_bins[i];
const double Null
Value for an Isis Null pixel.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
PixelType pixelType() const
const double ValidMinimum
The minimum valid double value for Isis pixels.
double multiplier() const
Returns the multiplier value for converting 8-bit/16-bit pixels to 32-bit.
Buffer for containing a three dimensional section of an image.
int GetNumPoints() const
Return the number of control points in the network.
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
void read(Blob &blob) const
This method will read data from the specified Blob object.
void CheckStatus()
Checks and updates the status.
Program progress reporter.
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
#define _FILEINFO_
Macro for the filename and line number.
int bandCount() const
Returns the number of virtual bands for the cube.
double base() const
Returns the base value for converting 8-bit/16-bit pixels to 32-bit.
QString ArraySubscriptNotInRange(int index)
This error should be used when an Isis object or application is checking array bounds and the legal r...
const double ValidMaximum
The maximum valid double value for Isis pixels.
Adds specific functionality to C++ strings.
const ControlMeasure * GetMeasure(QString serialNumber) const
Get a control measure based on its cube's serial number.
Functor for reduce using average functionality.
IO Handler for Isis Cubes.