Exemplo n.º 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 LevelScalingWithClipping()
{
  CHistLib Histogram;

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

  assert(!ImageLowContrast.empty());

  Mat ImageLowContrastClipped;

  // Perform the normalized clipping procedure
  double clipPercent = 50;
  Histogram.NormalizeClipImageBGR(ImageLowContrast, ImageLowContrastClipped, clipPercent);

  Mat HistImageLowContrastClipped;
  Histogram.ComputeAndDrawHistogramValue(ImageLowContrastClipped, HistImageLowContrastClipped);

  // Save the modified image
  string ImageLowContrastClippedName("fiveShadesLowContrastClipped.value.png");

  if (imwrite(ImageLowContrastClippedName, ImageLowContrastClipped))
  {
    cout << "Created clipped image: " << ImageLowContrastClippedName << endl;
  }

  // Save the histogram image
  string HistImageLowContrastClippedName("fiveShadesLowContrastClipped.value.hist.png");

  if (imwrite(HistImageLowContrastClippedName, HistImageLowContrastClipped))
  {
    cout << "Created value histogram: " << HistImageLowContrastClippedName << endl;
  }
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Description:
//  This examples draws an ascending ramp such that each histogram bar is
//  separated by one pixel.  The bars are colored red, the background is a
//  light shade of grey and the axis is black.  The height is chosen to fit the
//  height of the bars (if the height is too small the bars will simply get
//  cropped).
//-----------------------------------------------------------------------------
void DrawManuallyHistogram()
{
  // Declare histlib instance
  CHistLib Histogram;

  // Customize the display properties
  Histogram.SetPlotColor(Scalar(0x00, 0x00, 0xff));
  Histogram.SetAxisColor(Scalar(0x00, 0x00, 0x00));
  Histogram.SetBackgroundColor(Scalar(0xee, 0xee, 0xee));
  Histogram.SetHistImageHeight(133);
  Histogram.SetDrawSpreadOut(true);

  // Create a row vector for histogram values
  Mat Hist = Mat(128, 1, CV_32S);

  // The ith bin gets i
  for (int i = 0; i < Hist.rows; i++)
  {
    Hist.at<int>(i,0) = i;
  }

  Mat HistImage;
  Histogram.DrawHistogram(Hist, HistImage);

  string ImageName("ramp.hist.png");

  if (imwrite(ImageName, HistImage))
  {
    cout << "Created single channel histogram: " << ImageName << endl;
  }
}
Exemplo n.º 3
0
void draw_Histogram(const cv::Mat &src_im, cv::Mat &hist_im){
    //use filitchp made libraly
    //github : "https://github.com/filitchp/opencv-histlib"
    //
    //引数 -> 入力画像,ヒストグラム用のMat型

    cv::Mat dst;
    if(src_im.channels() == 1) cv::cvtColor(src_im, dst, CV_GRAY2BGR);
    else src_im.copyTo(dst);

    CHistLib *Histogram = new CHistLib;
    cv::MatND HistB, HistG, HistR;

    Histogram->ComputeHistogramBGR(dst, HistB, HistG, HistR);
    Histogram->DrawHistogramBGR(HistB, HistG, HistR, hist_im);

    delete Histogram;
}
Exemplo n.º 4
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;
  }
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Description:
//   This example draws a value histogram from a test image.
//-----------------------------------------------------------------------------
void DrawSimpleValueHistogram()
{
  CHistLib Histogram;

  // Open the image
  Mat ImageBGR = imread("images/bars.png");
  assert(!ImageBGR.empty());

  // Generate color histogram for the current image
  Mat HistImageGray;
  Histogram.ComputeAndDrawHistogramValue(ImageBGR, HistImageGray);

  // Save the histogram image
  string ImageName("bars.value.hist.png");

  if (imwrite(ImageName, HistImageGray))
  {
    cout << "Created value histogram: " << ImageName << endl;
  }
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------
// Description:
//   This example draws a color histogram from a test image.
// Note:
//  At first the large spike at zero might seem unintuitive, but it's there
//  because each channel has many pixels with the absence of color (0 values).
//  For example, if you had an image that was just blue, the red and green
//  channels would have lots of zeros and you would see a similar spike in at
//  zero in this type of histogram plot.
//-----------------------------------------------------------------------------
void DrawSimpleBgrHistogram()
{
  CHistLib Histogram;

  // Open the image
  Mat ImageBGR = imread("images/bars.png");
  assert(!ImageBGR.empty());

  // Generate histogram for the current image
  Mat HistImageBGR;
  Histogram.ComputeAndDrawHistogramBGR(ImageBGR, HistImageBGR);

  // Save the histogram image
  string ImageName("bars.rgb.hist.png");

  if (imwrite(ImageName, HistImageBGR))
  {
    cout << "Created BGR histogram: " << ImageName << endl;
  }
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
// Description:
//   This example draws a value histogram from a photo.  It is broken up into
//   two steps to show how get access to the histogram vector
//-----------------------------------------------------------------------------
void DrawPhotoValueHistogram()
{
  CHistLib Histogram;

  // Open the image
  Mat ImageBGR = imread("images/sunset.jpg");
  assert(!ImageBGR.empty());

  // Generate value channel histogram for the current image
  Mat HistImageGray;

  MatND Hist;
  Histogram.ComputeHistogramValue(ImageBGR, Hist);
  Histogram.DrawHistogramValue(Hist, HistImageGray);

  // Save the histogram image
  string ImageName("sunset.gray.hist.png");

  if (imwrite(ImageName, HistImageGray))
  {
    cout << "Created value histogram: " << ImageName << endl;
  }
}
Exemplo n.º 8
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;
  }
}
Exemplo n.º 9
0
//-----------------------------------------------------------------------------
// Description:
//   This example draws a color histogram from a photo. It is broken up into
//   two steps to show how get access to the histogram vectors
//-----------------------------------------------------------------------------
void DrawPhotoBgrHistogram()
{
  CHistLib Histogram;
  // Open the image
  Mat ImageBGR = imread("images/sunset.jpg");
  assert(!ImageBGR.empty());

  // Generate a color channel (BGR) histogram
  Mat HistImageBGR;

  MatND HistB;
  MatND HistG;
  MatND HistR;
  Histogram.ComputeHistogramBGR(ImageBGR, HistB, HistG, HistR);
  Histogram.DrawHistogramBGR(HistB, HistG, HistR, HistImageBGR);

  // Save the histogram image
  string ImageName("sunset.bgr.hist.png");

  if (imwrite(ImageName, HistImageBGR))
  {
    cout << "Created BGR histogram: " << ImageName << endl;
  }
}