/// <summary> /// Calculate the histogram for the region of interest and saves it under /// initialHistogram. /// </summary> private void UpdateHistogram() { // release the previous histogram if any. if (initialHistogram != null) { initialHistogram.Release(); } // if there's no image, just return. if (image == null) { return; } // we use symmetric bins and entire range. int[] bpBins = { NumberOfBins, NumberOfBins, NumberOfBins }; CVPair[] bpRanges = { new CVPair(0, 255), new CVPair(0, 255), new CVPair(0, 255) }; // calculate histogram for region of interest and display it in panel. image.RegionOfInterest = originalImage.SelectionRect; this.initialHistogram = image.CalcHistogram(bpBins, bpRanges); initHisto.ShowHistogram(image); image.ResetROI(); ResetSegmentation(); RefreshImages(); }
public void ShowHistogram(CVImage image, CVImage mask) { if (image == null) { return; } // split image into channels (b,g,r) CVImage[] planes = image.Split(); // we will create a 1D histogram for every channel. each histogram will have // 'numberOfBins' bins for its single dimension (ranged from 0 to 255). int[] bins = { BinsPerChannel }; CVPair[] ranges = { new CVPair(0, 255) }; // calculate histogram for red, green and blue channels (seperately). CVHistogram histoRed = planes[0].CalcHistogram(bins, ranges, mask); CVHistogram histoBlue = planes[1].CalcHistogram(bins, ranges, mask); CVHistogram histoGreen = planes[2].CalcHistogram(bins, ranges, mask); // dispose of plane images. foreach (CVImage img in planes) { img.Release(); } // draw the three histograms. DrawHistogram(bluePanel, histoBlue, 1); DrawHistogram(greenPanel, histoGreen, 2); DrawHistogram(redPanel, histoRed, 0); histoBlue.Release(); histoGreen.Release(); histoRed.Release(); }