Exemple #1
0
  //! Compute automatic stretch for a portion of the cube
  void ChipViewport::computeStretch(Stretch &stretch, bool force) {
    if (p_stretchLocked && !force) {
      stretch = *p_stretch;
    }
    else {
      Statistics stats;
      for (int line = 1; line < p_chip->Lines(); line++) {
        for (int samp = 1; samp < p_chip->Samples(); samp++) {
          double value = p_chip->GetValue(samp, line);
          stats.AddData(&value, 1);
        }
      }

      Histogram hist(stats.BestMinimum(), stats.BestMaximum());
      for (int line = 1; line <= p_chip->Lines(); line++) {
        for (int samp = 1; samp <= p_chip->Samples(); samp++) {
          double value = p_chip->GetValue(samp, line);
          hist.AddData(&value, 1);
        }
      }

      stretch.ClearPairs();
      if (hist.Percent(0.5) != hist.Percent(99.5)) {
        stretch.AddPair(hist.Percent(0.5), 0.0);
        stretch.AddPair(hist.Percent(99.5), 255.0);
      }
      else {
        stretch.AddPair(-DBL_MAX, 0.0);
        stretch.AddPair(DBL_MAX, 255.0);
      }

      *p_stretch = stretch;
    }
  }
Exemple #2
0
  void Histogram::InitializeFromCube(Cube &cube, const int band, Progress *progress) {
    // Make sure band is valid
    if ((band < 0) || (band > cube.Bands())) {
      string msg = "Invalid band in [Histogram constructor]";
      throw Isis::iException::Message(Isis::iException::Programmer,msg,_FILEINFO_);
    }

    double min,max;
    int nbins;

    if (cube.PixelType() == Isis::UnsignedByte) {
      min = 0.0 * cube.Multiplier() + cube.Base();
      max = 255.0 * cube.Multiplier() + cube.Base();
      nbins = 256;
    }
    else if (cube.PixelType() == Isis::SignedWord) {
      min = -32768.0 * cube.Multiplier() + cube.Base();
      max = 32767.0 * cube.Multiplier() + cube.Base();
      nbins = 65536;
    }
    else if (cube.PixelType() == Isis::Real) {
      // Determine the band for statistics
      int bandStart = band;
      int bandStop = band;
      int maxSteps = cube.Lines();
      if (band == 0){
        bandStart = 1;
        bandStop = cube.Bands();
        maxSteps = cube.Lines() * cube.Bands();
      }

      // Construct a line buffer manager and a statistics object
      LineManager line(cube);
      Statistics stats = Statistics();

      // Prep for reporting progress if necessary
      if (progress != NULL) {
        string save = progress->Text ();
        progress->SetText("Computing min/max for histogram");
        progress->SetMaximumSteps(maxSteps);
        progress->CheckStatus();
      }

      for (int useBand = bandStart ; useBand <= bandStop ; useBand++){
        // Loop and get the statistics for a good minimum/maximum
        for (int i=1; i<=cube.Lines(); i++) {
          line.SetLine(i,useBand);
          cube.Read(line);
          stats.AddData (line.DoubleBuffer(),line.size());
          if (progress != NULL) progress->CheckStatus();
        }
      }

      // Get the min/max for constructing a histogram object
      if (stats.ValidPixels() == 0) {
        min = 0.0;
        max = 1.0;
      }
      else {
        min = stats.BestMinimum ();
        max = stats.BestMaximum ();
      }

      nbins = 65536;
    }
    else {
      std::string msg = "Unsupported pixel type";
      throw iException::Message(Isis::iException::Programmer,msg,_FILEINFO_);
    }

    // Set the bins and range
    SetBinRange(min,max);
    SetBins(nbins);
  }