コード例 #1
0
        // draw the (top left corner of the) original image but with the segment boundaries overlayed in blue
        public void overlaySegmentation(string filename, int N, SegmentationService segmentation)
        {
            var newImage = new TiffImage(1 << N, 1 << N);

            var BLUE = unchecked ((int)0xFFFF0000); // ABGR

            for (var y = 0; y < newImage.height; y++)
            {
                for (var x = 0; x < newImage.width; x++)
                {
                    //var a = segmentation(x, y);
                    //var b = segmentation(x - 1, y);
                    //var c = segmentation(x, y - 1);
                    if (x == newImage.width - 1 || x == 0 || !segmentation.Segmentation(x, y).Equals(segmentation.Segmentation(x - 1, y)) ||
                        y == newImage.height - 1 || y == 0 || !segmentation.Segmentation(x, y).Equals(segmentation.Segmentation(x, y - 1)))
                    {
                        newImage.setColour(x, y, BLUE);
                    }
                    else
                    {
                        newImage.setColour(x, y, getColour(x, y));
                    }
                }
            }

            newImage.saveImage(filename);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var image = new TiffImage("..\\TestImages\\L15-3792E-1717N-Q4.tif");

            var N         = 5;
            var threshold = 800.0F;

            var segmentation = new SegmentationService(image, N, threshold);

            image.overlaySegmentation("segmentedN" + N + ".tif", N, segmentation);
        }
コード例 #3
0
        private void Process()
        {
            Bitmap bitmapFromScreen = BitmapService.BitmapFromScreen(CaptureArea.Width, CaptureArea.Height, CaptureArea.Left, CaptureArea.Top, this.comboBoxScreen.SelectedIndex);

            pictureBox1.Image = bitmapFromScreen;


            projectionBitMapFilter = ProjectionService.ProjectandFilter(SelectedColor, Convert.ToInt32(this.numericUpDownColorMargin.Value), bitmapFromScreen);
            ProjectionsToChartSeries(projectionBitMapFilter);
            ProjectionsToChartSeries(projectionBitMapFilter);
            this.pictureBox2.Image = projectionBitMapFilter.Bitmap;

            projectionBitMapFilter.HorizontalSegments = ProjectionService.ToSegments(projectionBitMapFilter.HorizontalProjection, projectionBitMapFilter.Bitmap.Height);
            projectionBitMapFilter.VerticalSegments   = new List <Segment>();

            if (SubtitlesDetected(projectionBitMapFilter.HorizontalSegments))
            {
                long  Range        = projectionBitMapFilter.HorizontalSegments[0].End - projectionBitMapFilter.HorizontalSegments[0].Starts;
                Int64 AverageRange = MathHelper.Average(Ranges);

                projectionBitMapFilter.VerticalSegments = ProjectionService.ToSegments(projectionBitMapFilter.VerticalProjection, projectionBitMapFilter.Bitmap.Height);

                if (projectionBitMapFilter.VerticalSegments.Count != 0)
                {
                    projectionBitMapFilter = ProjectionService.MaxMinEvaluation(bitmapFromScreen.Height, projectionBitMapFilter);

                    List <Segment> GroupedSegments = SegmentationService.GroupSegments(projectionBitMapFilter.VerticalSegments);

                    Bitmap bitmapInitialSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();
                    Bitmap bitmapGroupedSegments = (Bitmap)projectionBitMapFilter.Bitmap.Clone();

                    this.pictureBox2.Image                = BitmapService.DrawSegmentsinBitmap(projectionBitMapFilter.VerticalSegments, bitmapInitialSegments, Brushes.DarkRed);
                    this.pictureBoxGrouped.Image          = BitmapService.DrawSegmentsinBitmap(GroupedSegments, bitmapGroupedSegments, Brushes.Orange);
                    projectionBitMapFilter.CroppedBitmaps = BitmapService.ExtractCropBitmaps(GroupedSegments, projectionBitMapFilter.Bitmap);


                    foreach (Bitmap crop in projectionBitMapFilter.CroppedBitmaps)
                    {
                        var margin = BitmapService.CorrectMargin(crop);

                        projectionBitMapFilter.CorrectedMarginBitmaps.Add(margin);
                    }



                    List <char> predictions = new List <char>();

                    foreach (Bitmap bitmap in projectionBitMapFilter.CorrectedMarginBitmaps)
                    {
                        Bitmap resized = BitmapService.ResizeImage(bitmap, 32, 32);

                        projectionBitMapFilter.ResizedBitmaps.Add(resized);

                        string zerosandones = DatasetGenerator.ToZerosOnesSequence(' ', resized);

                        var c = PredictionService.Predict(zerosandones);
                        predictions.Add(c);

                        x++;
                    }

                    BitmapsToScreen(projectionBitMapFilter.ResizedBitmaps);

                    AddTextBoxToScreen(projectionBitMapFilter.CroppedBitmaps.Count, predictions);
                }
            }
        }