Exemplo n.º 1
0
        private async void ExtractParts(Bitmap bitmap, Bitmap originalBitmap)
        {
            var binarizedImage = BitmapBinarizer.Process(bitmap);
            var linesTask      = HoughTransform.GetLines(binarizedImage);
            var circlesTask    = HoughTransform.GetCircles(binarizedImage);
            var strip          = DoPerformStrip.IsChecked;

            var viewModel = (ImagesGrid.DataContext) as ImageViewModel;

            if (viewModel == null)
            {
                return;
            }
            viewModel.Clear();

            var rectanglesBitmapsTask = RectanglesExtractor.Extract(bitmap, originalBitmap, binarizedImage, await linesTask, strip);

            pbStatus.Value = 40;
            var trianglesBitmapsTask = TrianglesExtractor.Extract(bitmap, originalBitmap, binarizedImage, await linesTask, strip);

            pbStatus.Value = 60;
            var circleBitmapsTask = CirclesExtractor.Extract(bitmap, originalBitmap, await circlesTask, strip);

            pbStatus.Value = 80;

            var rectanglesBitmaps = await rectanglesBitmapsTask;

            foreach (var rectangleBitmap in rectanglesBitmaps[0])
            {
                viewModel.Rectangles.Add(new ImageModel(BitmapConverter.GetBitmapSource(rectangleBitmap)));
            }

            var trianglesBitmaps = await trianglesBitmapsTask;

            foreach (var triangleBitmap in trianglesBitmaps[0])
            {
                viewModel.Triangles.Add(new ImageModel(BitmapConverter.GetBitmapSource(triangleBitmap)));
            }

            var circleBitmaps = await circleBitmapsTask;

            foreach (var circlesBitmap in circleBitmaps[0])
            {
                viewModel.Circles.Add(new ImageModel(BitmapConverter.GetBitmapSource(circlesBitmap)));
            }
            PerformClassification(circleBitmaps, trianglesBitmaps, rectanglesBitmaps, viewModel);
            pbStatus.Value = 100;
        }
Exemplo n.º 2
0
        private async void ProcessFolder_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new FolderBrowserDialog
            {
                SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)
            };
            var result = dialog.ShowDialog(this.GetIWin32Window());

            var storage = new Dictionary <string, Bitmap>();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                foreach (var path in Directory.EnumerateFiles(dialog.SelectedPath, "*.*", SearchOption.AllDirectories)
                         .Where(file => _imageFileExtensions.Any(x => file.EndsWith(x, StringComparison.OrdinalIgnoreCase))))
                {
                    var bitmap = BitmapConverter.GetBitmap(new BitmapImage(new Uri(path)));
                    bitmap = (from object filterObject in FiltersMenu.ItemsSource
                              select(filterObject as FilterModel) into filterModel
                              where filterModel.Enabled
                              select filterModel.Filter)
                             .Aggregate(bitmap, (current, filter) => filter.Process(current));

                    var binarizedImage = BitmapBinarizer.Process(bitmap);
                    var linesTask      = HoughTransform.GetLines(binarizedImage);
                    var circlesTask    = HoughTransform.GetCircles(binarizedImage);

                    var rectanglesBitmaps = await RectanglesExtractor.Extract(bitmap, bitmap, binarizedImage, await linesTask, true);

                    var trianglesBitmaps = await TrianglesExtractor.Extract(bitmap, bitmap, binarizedImage, await linesTask, true);

                    var circleBitmaps = await CirclesExtractor.Extract(bitmap, bitmap, await circlesTask, true);

                    bitmap =
                        rectanglesBitmaps[0].Concat(trianglesBitmaps[0])
                        .Concat(circleBitmaps[0])
                        .OrderBy(b => b.Width * b.Height).Last();
                    storage.Add(path, bitmap);
                }
            }

            foreach (var element in storage)
            {
                BilinearInterpolation.Resize(element.Value, ResizeWidth, ResizeHeight)
                .Save(element.Key + ".processed.bmp", ImageFormat.Bmp);
            }
        }