static Histogram ComputeChannelHistogram(IplImage channel) { var histogram = new Histogram(1, new[] { 256 }, HistogramType.Array, new[] { new[] { 0, 256f } }); histogram.CalcArrHist(new[] { channel }); histogram.Normalize(1); return(histogram); }
public void Normalize_UniformHistogram_SumOfBinsEqualsOne() { var factor = 1.0; var hist = new Histogram(1, new[] { 100 }, HistogramType.Array, new[] { new[] { 0, 256f } }); var diag = Mat.Eye(50, 50, Depth.U8, 1); hist.CalcArrHist(new[] { diag }); hist.Normalize(factor); var sum = CV.Sum(hist.Bins).Val0; Assert.AreEqual(factor, sum); }
public Histogram CummulativeHistogram() { var histogram = new Histogram(256, new[] { 0, 256 }, HistogramType.Array); histogram.CalcArrHist(new[] { GradientMap }); histogram.Normalize(1.0); var cummulative = histogram.Bins.GetReal(0); for (var index = 1; index < 256; index++) { cummulative += histogram.Bins.GetReal(index); histogram.Bins.SetReal(index, cummulative); } return(histogram); }
public IObservable <Mat> Process <TArray>(IObservable <TArray> source) where TArray : Arr { return(Observable.Defer(() => { var histogram = new Histogram(1, new[] { Bins }, HistogramType.Array, new[] { new[] { Min, Max } }); histogram.Clear(); return source.Select(input => { histogram.CalcArrHist(new[] { input }, Accumulate); if (Normalize) { histogram.Normalize(1); } var output = histogram.Bins.GetMat(true).Reshape(0, 1); return output.Clone(); }); })); }