Beispiel #1
0
        public void MakeHistogramData()
        {
            Bitmap     bmp    = new Bitmap(image);
            BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    int value;

                    if (settings.discretizeMethod == DiscretizeMethod.DiscretizeForeground)
                    {
                        value = discretize.DiscretizeValueForeground(i, j, bmData);
                    }
                    else
                    {
                        value = discretize.DiscretizeValue(i, j, bmData);
                    }

                    histogramData[value]++;
                }

                progressUpdated((double)i / ((double)image.Width - 1));
            }

            bmp.UnlockBits(bmData);

            //Now scale the data logarithmically

            int pixels = image.Width * image.Height;

            for (int i = 0; i < histogramData.Length; i++)
            {
                int point = (int)((innerPanel.Height) * (1.0 - Math.Log(histogramData[i]) / Math.Log(pixels)) + 0.5);

                if (point < 0)
                {
                    point = 0;
                }
                else if (point > innerPanel.Height)
                {
                    point = innerPanel.Height;
                }

                displayData[i] = point;
            }
        }