6

I want to create a histogram within a C# program that uses EMGU. EMGU contains a class called MCvHistogram in it, but I don't know how to use it.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
White Dwarf
  • 189
  • 1
  • 3
  • 11
  • This article shows how to create histogram in RGB http://stackoverflow.com/questions/8204822/how-to-draw-histogram-using-emgucv-and-c-sharp – JiP Jan 14 '14 at 16:05

2 Answers2

11

You should use DenseHistogram class if you want to use EmguCV. I'll show you basic usage:

  // Create a grayscale image
  Image<Gray, Byte> img = new Image<Gray, byte>(400, 400);
  // Fill image with random values
  img.SetRandUniform(new MCvScalar(), new MCvScalar(255));
  // Create and initialize histogram
  DenseHistogram hist = new DenseHistogram(256, new RangeF(0.0f, 255.0f));
  // Histogram Computing
  hist.Calculate<Byte>(new Image<Gray, byte>[] { img }, true, null);

There are a lot of other common methods inside DenseHistogram class such as Back Projection

Luca Del Tongo
  • 2,702
  • 16
  • 18
  • thanx.. but i already calculate histogram using CvInvoke.cvCalHist(), but i find above method is much easier to use. Can you briefly elaborate difference between McvHistogram and DenseHistogram? – White Dwarf Feb 07 '11 at 04:35
  • 2
    DenseHistogram is the managed class that wraps McvHistogram. You can inspect DenseHistogram class and check that it has a property MCvHistogram. My suggestion is to not use cvinvoke when opencv functionality has already been wrapped in proper managed class... – Luca Del Tongo Feb 07 '11 at 10:22
3

You can use this code snippet:

histogramBox.GenerateHistograms(image,bin);               
histogramBox2.Refresh();

It will create a histogram of your picture automatically.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
HazzA
  • 31
  • 1