7#include "ImageHistogram.h" 
   10#include "ControlNet.h" 
   11#include "ControlMeasure.h" 
   57      double startSample, 
double startLine,
 
   58      double endSample, 
double endLine,
 
   59      int bins, 
bool addCubeData) {
 
   60    InitializeFromCube(cube, statsBand, progress, bins, startSample, startLine,
 
   64      Brick cubeDataBrick((
int)(endSample - startSample + 1),
 
   68      int startBand = statsBand;
 
   69      int endBand = statsBand;
 
   76      if (progress != NULL) {
 
   77        progress->
SetText(
"Gathering histogram");
 
   79          (
int)(endLine - startLine + 1) * (
int)(endBand - startBand + 1));
 
   83      for (
int band = startBand; band <= endBand; band++) {
 
   84        for (
int line = (
int)startLine; line <= endLine; line++) {
 
   85          cubeDataBrick.SetBasePosition(qRound(startSample), line, band);
 
   86          cube.
read(cubeDataBrick);
 
   87          AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size());
 
   88          if (progress != NULL) {
 
 
   96  void ImageHistogram::InitializeFromCube(
Cube &cube, 
int statsBand,
 
   97      Progress *progress, 
int nbins, 
double startSample, 
double startLine,
 
   98      double endSample, 
double endLine) {
 
  100    if ( (statsBand < 0) || (statsBand > cube.
bandCount() ) ) {
 
  101      string msg = 
"Cannot gather histogram for band [" + 
IString(statsBand) +
 
  108    double minDnValue = 
Null;
 
  109    double maxDnValue = 
Null;
 
  120    else if (cube.
pixelType() == UnsignedWord) {
 
  127    else if (cube.
pixelType() == SignedWord) {
 
  138    else if (cube.
pixelType() == UnsignedInteger ||
 
  146      IString msg = 
"Unsupported pixel type";
 
  150    if (startSample == 
Null)
 
  153    if (endSample == 
Null)
 
  156    if (startLine == 
Null)
 
  163    if (minDnValue == 
Null || maxDnValue == 
Null) {
 
  165      Brick cubeDataBrick((
int)(endSample - startSample + 1),
 
  172      int startBand = statsBand;
 
  173      int endBand = statsBand;
 
  175      if (statsBand == 0) {
 
  180      if (progress != NULL) {
 
  182        progress->
SetText(
"Computing min/max for histogram");
 
  184          (
int)(endLine - startLine + 1) * (
int)(endBand - startBand + 1) );
 
  188      for (
int band = startBand; band <= endBand; band++) {
 
  189        for (
int line = (
int)startLine; line <= endLine; line++) {
 
  191          cubeDataBrick.SetBasePosition(qRound(startSample), line, band);
 
  192          cube.
read(cubeDataBrick);
 
  193          stats.AddData(cubeDataBrick.DoubleBuffer(), cubeDataBrick.size());
 
  195          if (progress != NULL) {
 
  201      if (stats.ValidPixels() == 0) {
 
  206        minDnValue = stats.Minimum();
 
  207        maxDnValue = stats.Maximum();
 
  229                          const unsigned int count) {
 
  232    int nbins = 
p_bins.size();
 
  234    for (
unsigned int i = 0; i < count; i++) {
 
  236        if (BinRangeStart() == BinRangeEnd() ) {
 
  240          index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
 
  241                              (data[i] - BinRangeStart() ) + 0.5);
 
  243        if (index < 0) index = 0;
 
  244        if (index >= nbins) index = nbins - 1;
 
 
  259    int nbins = 
p_bins.size();
 
  262      if (BinRangeStart() == BinRangeEnd() ) {
 
  266        index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart() ) *
 
  267                            (data - BinRangeStart() ) + 0.5);
 
  269      if (index < 0) index = 0;
 
  270      if (index >= nbins) index = nbins - 1;
 
 
  285                             const unsigned int count) {
 
  288    int nbins = 
p_bins.size();
 
  290    for (
unsigned int i = 0; i < count; i++) {
 
  293        if (BinRangeStart() == BinRangeEnd() ) {
 
  297          index = (int) floor((
double)(nbins - 1) / (BinRangeEnd() - BinRangeStart()) *
 
  298                              (data[i] - BinRangeStart()) + 0.5);
 
  300        if (index < 0) index = 0;
 
  301        if (index >= nbins) index = nbins - 1;
 
 
  319                                double &low, 
double &high)
 const {
 
  320    if ( (index < 0) || (index >= (
int)
p_bins.size() ) ) {
 
  326    double binSize = (BinRangeEnd() - BinRangeStart()) / (
double)(
p_bins.size() - 1);
 
  327    low = BinRangeStart() - binSize / 2.0 + binSize * (double) index;
 
  328    high = low + binSize;
 
 
Buffer for containing a three dimensional section of an image.
 
IO Handler for Isis Cubes.
 
double multiplier() const
Returns the multiplier value for converting 8-bit/16-bit pixels to 32-bit.
 
double base() const
Returns the base value for converting 8-bit/16-bit pixels to 32-bit.
 
PixelType pixelType() const
 
void read(Blob &blob, const std::vector< PvlKeyword > keywords=std::vector< PvlKeyword >()) const
This method will read data from the specified Blob object.
 
virtual int bandCount() const
Returns the number of virtual bands for the cube.
 
Container of a cube histogram.
 
void SetBins(const int bins)
Change the number of bins in the histogram and reset counters.
 
std::vector< BigInt > p_bins
The array of counts.
 
void SetValidRange(const double minimum=Isis::ValidMinimum, const double maximum=Isis::ValidMaximum)
Changes the range of the bins.
 
@ Programmer
This error is for when a programmer made an API call that was illegal.
 
Adds specific functionality to C++ strings.
 
ImageHistogram(double minimum, double maximum, int bins=1024)
Constructs a histogram object.
 
virtual void AddData(const double *data, const unsigned int count)
Add an array of doubles to the histogram counters.
 
virtual void RemoveData(const double *data, const unsigned int count)
Remove an array of doubles from the histogram counters.
 
~ImageHistogram()
Destructs a histogram object.
 
virtual void BinRange(const int index, double &low, double &high) const
Returns the left edge and right edge values of a bin.
 
Program progress reporter.
 
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
 
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
 
void CheckStatus()
Checks and updates the status.
 
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
 
void RemoveData(const double *data, const unsigned int count)
Remove an array of doubles from the accumulators and counters.
 
Statistics(QObject *parent=0)
Constructs an IsisStats object with accumulators and counters set to zero.
 
QString ArraySubscriptNotInRange(int index)
This error should be used when an Isis object or application is checking array bounds and the legal r...
 
This is free and unencumbered software released into the public domain.
 
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
 
const double Null
Value for an Isis Null pixel.
 
Namespace for the standard library.