How to draw histogram using EmguCV and C#

后端 未结 4 2009
礼貌的吻别
礼貌的吻别 2020-12-28 23:31

I need to draw two types of histogram, namely monodimensional and tridimensional. I\'m a newbie to EMGU and all of the samples I found on the net are in C++ or C. Are there

4条回答
  •  没有蜡笔的小新
    2020-12-28 23:42

    Tridimensional histogram

    Image[] inp = new Image("fileName.jpg");
    int nBins = 256;
    DenseHistogram hist = new DenseHistogram(new int[] { nBins, nBins, nBins }, new RangeF[] { new RangeF(0, 255), new RangeF(0, 255), new RangeF(0, 255) });
    hist.Calculate(inp.Split(), false, null);
    
    // To get value of single bin
    int b = 255; int g = 0; int r = 0;  //blue
    int count = Convert.ToInt32(hist.MatND.ManagedArray.GetValue(b, g, r));  //count = no of pixels in color Bgr(b,g,r)
    
    //To get all values in a single array
    List> histVal = new List>(nBins * nBins * nBins);
    for (int i = 0; i < nBins; i++)
        for (int j = 0; j < nBins; j++)
            for (int k = 0; k < nBins; k++)
                histVal.Add(new Tuple(new Bgr(i, j, k), Convert.ToInt32(hist.MatND.ManagedArray.GetValue(i, j, k))));
    

    Monodimensional histogram

    int nBins = 256;
    float[] valHist = new float[nBins];
    Image[] inp = new Image("fileName.jpg");
    DenseHistogram hist = new DenseHistogram(nBins, new RangeF(0, 255));
    hist.Calculate(new Image[] { inp }, true, null);
    hist.MatND.ManagedArray.CopyTo(valHist,0);
    

提交回复
热议问题