Ejemplo n.º 1
0
        /// <summary>
        /// Analyze the scanline Scanline around point XCenter
        /// </summary>
        public void Analyze()
        {
            if (!XCenter.HasValue && !ScanLine.HasValue)
            {
                throw new Exception();
            }

            int    x       = (int)XCenter;
            int    y       = (int)ScanLine;
            double start   = Image[x, y];
            double meanMax = 0.0;

            var stats = new RunningStatistics(5);

            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            int    dx = x - 1;
            double stdDev;
            double mean;

            do
            {
                stats.Add(Image[--dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean   = stats.Mean;
                if (mean > meanMax)
                {
                    meanMax = mean;
                }
            } while (Math.Abs(mean - LeftBackground) > 3 * LeftBackgroundDeviation);

            LeftBackgroundPosition  = dx + 1;
            LeftBackground          = mean;
            LeftBackgroundDeviation = stdDev;

            stats.Clear(5);
            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            dx = x + 1;
            do
            {
                stats.Add(Image[++dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean   = stats.Mean;
                if (mean > meanMax)
                {
                    meanMax = mean;
                }
            } while (Math.Abs(mean - RightBackground) > 3 * RightBackgroundDeviation);

            RightBackgroundPosition  = dx - 1;
            RightBackground          = mean;
            RightBackgroundDeviation = stdDev;

            IsBackgroundLine = (Math.Abs(meanMax - LeftBackground) < 3 * LeftBackgroundDeviation) &&
                               (Math.Abs(meanMax - RightBackground) < 3 * RightBackgroundDeviation);
        }
Ejemplo n.º 2
0
        public bool FindBackground()
        {
            if (!XCenter.HasValue && !ScanLine.HasValue)
            {
                throw new Exception();
            }

            int    x     = (int)XCenter;
            int    y     = (int)ScanLine;
            double start = Image[x, y];

            var stats = new RunningStatistics(5);

            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            int    dx = x - 1;
            double stdDev;
            double mean;
            double lastVariance;

            do
            {
                lastVariance = stats.Variance;
                stats.Add(Image[--dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean   = stats.Mean;
            } while (stats.Variance < lastVariance || Math.Abs(mean - start) < 3 * stdDev);

            LeftBackgroundPosition  = dx + 1;
            LeftBackground          = mean;
            LeftBackgroundDeviation = stdDev;

            stats.Clear(5);
            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            dx = x + 1;
            do
            {
                lastVariance = stats.Variance;
                stats.Add(Image[++dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean   = stats.Mean;
            } while (stats.Variance < lastVariance || Math.Abs(mean - start) < 3 * stdDev);

            RightBackgroundPosition  = dx - 1;
            RightBackground          = mean;
            RightBackgroundDeviation = stdDev;

            IsBackgroundLine = false;

            return(true);
        }
Ejemplo n.º 3
0
        public bool FindBackground()
        {
            if (!XCenter.HasValue && !ScanLine.HasValue)
            {
                throw new Exception();
            }

            int x = (int)XCenter;
            int y = (int)ScanLine;
            double start = Image[x, y];

            var stats = new RunningStatistics(5);

            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            int dx = x- 1;
            double stdDev;
            double mean;
            double lastVariance;
            do
            {
                lastVariance = stats.Variance;
                stats.Add(Image[--dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean = stats.Mean;
            } while (stats.Variance < lastVariance || Math.Abs(mean - start) < 3 * stdDev);

            LeftBackgroundPosition = dx + 1;
            LeftBackground = mean;
            LeftBackgroundDeviation = stdDev;

            stats.Clear(5);
            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            dx = x + 1;
            do
            {
                lastVariance = stats.Variance;
                stats.Add(Image[++dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean = stats.Mean;
            } while (stats.Variance < lastVariance || Math.Abs(mean - start) < 3 * stdDev);

            RightBackgroundPosition = dx - 1;
            RightBackground = mean;
            RightBackgroundDeviation = stdDev;

            IsBackgroundLine = false;

            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Analyze the scanline Scanline around point XCenter
        /// </summary>
        public void Analyze()
        {
            if (!XCenter.HasValue && !ScanLine.HasValue)
            {
                throw new Exception();
            }

            int x = (int)XCenter;
            int y = (int)ScanLine;
            double start = Image[x, y];
            double meanMax = 0.0;

            var stats = new RunningStatistics(5);

            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            int dx = x - 1;
            double stdDev;
            double mean;
            do
            {
                stats.Add(Image[--dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean = stats.Mean;
                if (mean > meanMax)
                {
                    meanMax = mean;
                }
            } while (Math.Abs(mean - LeftBackground) > 3 * LeftBackgroundDeviation);

            LeftBackgroundPosition = dx + 1;
            LeftBackground = mean;
            LeftBackgroundDeviation = stdDev;

            stats.Clear(5);
            stats.Add(Image[x, y]);
            stats.Add(Image[x - 1, y]);

            dx = x + 1;
            do
            {
                stats.Add(Image[++dx, y]);
                stdDev = Math.Sqrt(stats.Variance);
                mean = stats.Mean;
                if (mean > meanMax)
                {
                    meanMax = mean;
                }
            } while (Math.Abs(mean - RightBackground) > 3 * RightBackgroundDeviation);

            RightBackgroundPosition = dx - 1;
            RightBackground = mean;
            RightBackgroundDeviation = stdDev;

            IsBackgroundLine = (Math.Abs(meanMax - LeftBackground) < 3 * LeftBackgroundDeviation) &&
                               (Math.Abs(meanMax - RightBackground) < 3 * RightBackgroundDeviation);
        }