コード例 #1
0
ファイル: ColorHistogram.cs プロジェクト: tdck/opencvdotnet
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private void UpdateHistogram()
        {
            int numberOfBins;

            if (!int.TryParse(binSize.Text, out numberOfBins))
            {
                statusBar.Text = string.Format("Number of bins '{0}' is not an integer.", binSize.Text);
                return;
            }

            if (image == null)
            {
                return;
            }

            //image.RegionOfInterest = originalImage.SelectionRect;

            // 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   = { numberOfBins };
            CVPair[] ranges = { new CVPair(0, 255) };

            // calculate histogram for red, green and blue channels (seperately).
            CVHistogram histoRed   = planes[0].CalcHistogram(bins, ranges);
            CVHistogram histoBlue  = planes[1].CalcHistogram(bins, ranges);
            CVHistogram histoGreen = planes[2].CalcHistogram(bins, ranges);

            // draw the three histograms.
            DrawHistogram(bluePanel, histoBlue, 1);
            DrawHistogram(greenPanel, histoGreen, 2);
            DrawHistogram(redPanel, histoRed, 0);

            // resize & put original image onto form.
            CVImage output     = new CVImage(image.Width, image.Height, CVDepth.Depth8U, 3);
            CVImage emptyPlane = new CVImage(image.Width, image.Height, CVDepth.Depth8U, 1);

            emptyPlane.Zero();

            CVImage[] images = new CVImage[3];
            images[0] = images[1] = images[2] = emptyPlane;

            if (blueCheck.Checked)
            {
                images[0] = planes[0];
            }
            if (greenCheck.Checked)
            {
                images[1] = planes[1];
            }
            if (redCheck.Checked)
            {
                images[2] = planes[2];
            }

            output.Merge(images);
            originalImage.Image = output.ToBitmap();

            // dispose of plane images.
            foreach (CVImage img in planes)
            {
                img.Dispose();
            }

            statusBar.Text = "Ready";
        }