Пример #1
0
 public SimpleSegmentator(Config configuration, AnalyzablePage analyzablePage)
 {
     GeneticConfiguration = configuration;
     _analyzablePage      = analyzablePage;
     _hystogram           = Functions.FeautureScaling(Hystogram.GetHystogram(_analyzablePage.Original));
     _width = _analyzablePage.Width;
 }
Пример #2
0
        public AnalyzablePage GetSegmentation()
        {
            if (_solution != null)
            {
                return(_solution);
            }

            Solve();
            _solution = Solution(BestOrganism);
            return(_solution);
        }
Пример #3
0
        private AnalyzablePage Solution(Organism organism)
        {
            try
            {
                var triggerValue = organism.Factors[0].Value;
                var minHeight    = organism.Factors[1].Value;
                var height       = _hystogram.GetLength(0);
                var page         = new AnalyzablePage(height, _width);

                int start = 0;

                var isLine = false;

                for (var y = 0; y < height; y++)
                {
                    var trigger = (_hystogram[y] > triggerValue);

                    if (trigger)
                    {
                        if (!isLine)
                        {
                            start  = y;
                            isLine = true;
                        }
                    }
                    else
                    {
                        if (isLine)
                        {
                            int end        = y;
                            var lineHeight = end - start + 1;
                            if (lineHeight > minHeight)
                            {
                                page.AddLine(new AnalyzableLine(start, lineHeight));
                            }
                            isLine = false;
                        }
                    }
                }

                return(page);
            }
            catch (Exception e)
            {
                throw new Exception("Cant generate solution", e);
            }
        }
Пример #4
0
        private void AnalyzePage()
        {
            AnalyzablePage page;

            Cursor  = Cursors.WaitCursor;
            Enabled = false;
            try { page = new AnalyzablePage(Page); }
            catch (Exception exception)
            {
                Enabled = true;
                MessageBox.Show(exception.Message, @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Status.Text = @"Автоматическое построение разметки...";
            page.SegmentatePage();
            Status.Text = "";
            Enabled     = true;
        }
Пример #5
0
        private void OwlFormLoad(object sender, EventArgs e)
        {
            var bitmap = new Bitmap(100, 100);

            try
            {
                bitmap = new Bitmap(@"Data/IMAGE.BMP");
            }
            catch (ArgumentException)
            {
                Application.Exit();
            }
            var page    = new AnalyzablePage(bitmap);
            var ranges  = page.Ranges();
            var points  = page.Summ;
            var factors = new List <GrayCode>();
            var str     = new StreamWriter("Ranges.dat");

            foreach (double t in ranges)
            {
                str.WriteLine(t);
            }

            str.Close();
            var str1 = new StreamWriter("Points.dat");

            foreach (double t in points)
            {
                str1.WriteLine(t);
            }
            str1.Close(); /*
                           * ranges = Repositories.Functions.FeautureScaling(ranges);
                           * points = Repositories.Functions.FeautureScaling(points);
                           * factors.Add(new GrayCode(0,-1,1));
                           * factors.Add(new GrayCode(0, 0, 1));
                           * factors.Add(new GrayCode(0, 0, 1)); */
            //var geneticAlgorithm = new GeneticAlgorithm(points, ranges, factors);
            //page.Lines = geneticAlgorithm.Solve();
            page.RenderLines(imageOutput);
        }
Пример #6
0
        protected override double Fitness(Organism organism)
        {
            try
            {
                AnalyzablePage segmentation  = Solution(organism);
                int            heightsRange  = segmentation.HeightRange();
                int            distanceRange = segmentation.DistanceRange();
                //double densityRange = segmentation.DensityRange();
                var    summ    = (segmentation.Lines.Count > 2) ? segmentation.Lines.Sum(line => line.Height) : 0;
                double fitness = 1 /
                                 ((double)(1 + heightsRange) * (1 + distanceRange) * (1 + Math.Abs(2 * segmentation.Height - summ)));

                if (!((fitness >= 0) && (fitness <= 1)))
                {
                    throw new ArgumentOutOfRangeException();
                }

                return(fitness);
            }
            catch (Exception e)
            {
                throw new Exception("Cant calculate fitness", e);
            }
        }