Example #1
0
//-----------------------------------------------------------------------------
// Description:
//   This example shows how to scale the value channel of an image.  This is
//   a potential way to implement an auto-contrast/auto-levels operation
//-----------------------------------------------------------------------------
void LevelScalingLowContrast()
{
  CHistLib Histogram;

  // Open the image
  Mat ImageLowContrast = imread("images/fiveShadesLowContrast.png");

  assert(!ImageLowContrast.empty());

  Mat ImageOriginalNorm;
  Mat ImageLowContrastNorm;

  // Generate color histogram for the current image
  Mat HistImageGray;

  Histogram.NormalizeImageBGR(ImageLowContrast, ImageLowContrastNorm);

  Mat HistImageLowContrast;
  Mat HistImageLowContrastNorm;

  Histogram.ComputeAndDrawHistogramValue(ImageLowContrast, HistImageLowContrast);
  Histogram.ComputeAndDrawHistogramValue(ImageLowContrastNorm, HistImageLowContrastNorm);

  // Save the histogram images
  string HistImageLowContrastName("fiveShadesLowContrast.value.hist.png");
  string HistImageLowContrastNormName("fiveShadesLowContrastNorm.value.hist.png");
  string ImageLowContrastNormName("fiveShadesLowContrastNorm.png");

  if (imwrite(HistImageLowContrastName, HistImageLowContrast))
  {
    cout << "Created value histogram: " << HistImageLowContrastName << endl;
  }

  if (imwrite(HistImageLowContrastNormName, HistImageLowContrastNorm))
  {
    cout << "Created value histogram: " << HistImageLowContrastNormName << endl;
  }

  if (imwrite(ImageLowContrastNormName, ImageLowContrastNorm))
  {
    cout << "Created normalized image: " << ImageLowContrastNormName << endl;
  }
}
Example #2
0
//-----------------------------------------------------------------------------
// Description:
//   This example shows how to scale the value channel of an image.  This is
//   a potential way to implement an auto-contrast/auto-levels operation
//-----------------------------------------------------------------------------
void LevelScalingNoEffect()
{
  CHistLib Histogram;

  // Open the image
  Mat ImageOriginal = imread("images/fiveShades.png");

  assert(!ImageOriginal.empty());

  Mat ImageOriginalNorm;

  // Generate color histogram for the current image
  Mat HistImageGray;

  // Used to verify that this operation does not modify the original image
  Histogram.NormalizeImageBGR(ImageOriginal, ImageOriginalNorm);

  Mat HistImageOriginal;
  Mat HistImageOriginalNorm;

  Histogram.ComputeAndDrawHistogramValue(ImageOriginal, HistImageOriginal);
  Histogram.ComputeAndDrawHistogramValue(ImageOriginalNorm, HistImageOriginalNorm);

  // Save the histogram images
  string HistImageOriginalName("fiveShades.value.hist.png");
  string HistImageOriginalNormName("fiveShadesNorm.value.hist.png");

  if (imwrite(HistImageOriginalName, HistImageOriginal))
  {
    cout << "Created value histogram: " << HistImageOriginalName << endl;
  }

  if (imwrite(HistImageOriginalNormName, HistImageOriginalNorm))
  {
    cout << "Created value histogram: " << HistImageOriginalNormName << endl;
  }
}