Пример #1
0
        ////////////////////////////////////////////////////////////

        // Tracing ImageData, then returning PaddedPaletteImage with tracedata in layers
        private static TracedImage PaddedPaletteImageToTraceData(Bitmap image, Tracing tracing, SvgRendering rendering)
        {
            // Selective Gaussian blur preprocessing
            //if (options.Blur.BlurRadius > 0)
            //{
            //    // TODO: This seems to not work currently.
            //    imgd = Blur(imgd, options.Blur.BlurRadius, options.Blur.BlurDelta);
            //}

            // 1. Color quantization
            var colors      = image.ChangeFormat(PixelFormat.Format32bppArgb).ToColorReferences();
            var colorGroups = ColorGrouping.Convert(colors, image.Width, image.Height, Palette);
            // 2. Layer separation and edge detection
            var rawLayers = Layering.Convert(colorGroups, image.Width, image.Height, Palette);
            // 3. Batch pathscan
            var pathPointLayers = rawLayers.ToDictionary(cl => cl.Key, cl => new Layer <PathPointPath>
            {
                Paths = Pathing.Scan(cl.Value, tracing.PathOmit).ToList()
            });
            // 4. Batch interpollation
            var interpolationPointLayers = pathPointLayers.ToDictionary(cp => cp.Key, cp => Interpolation.Convert(cp.Value));
            // 5. Batch tracing
            var sequenceLayers = interpolationPointLayers.ToDictionary(ci => ci.Key, ci => new Layer <SequencePath>
            {
                Paths = ci.Value.Paths.Select(path => new SequencePath
                {
                    Path      = path,
                    Sequences = Sequencing.Create(path.Points.Select(p => p.Direction).ToList()).ToList()
                }).ToList()
            });

            var segmentLayers = sequenceLayers.ToDictionary(ci => ci.Key, ci => new Layer <SegmentPath>
            {
                Paths = ci.Value.Paths.Select(path => new SegmentPath
                {
                    Segments = path.Sequences.Select(s => Segmentation.Fit(path.Path.Points, s, tracing, rendering)).SelectMany(s => s).ToList()
                }).ToList()
            });

            return(new TracedImage(segmentLayers, image.Width, image.Height));
        }
Пример #2
0
        private void Part5Button_Click(object sender, RoutedEventArgs e)
        {
            if (!_part5Compete)
            {
                _interpolationPointLayers = _pathPointLayers.ToDictionary(cp => cp.Key, cp => Interpolation.Convert(cp.Value));
                var paths = _interpolationPointLayers.SelectMany(cl => cl.Value.Paths.Select(p => new { Color = cl.Key, p.Points })).ToList();
                if (true)
                {
                    double gridWidth  = _loadedImage.Width;
                    double gridHeight = _loadedImage.Height;
                    var    offset     = CalculateScaledOffsets(ref gridWidth, ref gridHeight);
                    _gridWidth  = gridWidth;
                    _gridHeight = gridHeight;

                    var lines = new List <UIElement>();
                    foreach (var path in paths)
                    {
                        var color  = path.Color.Color;
                        var brush  = new SolidColorBrush(MColor.FromArgb(color.A, color.R, color.G, color.B));
                        var points = path.Points.Select(p => new Point <double> {
                            X = p.X, Y = p.Y
                        }).ToList();
                        var pathLines = CreateOverlayLines(points, offset, brush, 10.0, false);
                        lines.AddRange(pathLines);
                    }

                    _interpLines = lines;
                }
                //_interpLines = new List<UIElement>();
                _part5Compete       = true;
                InterpCount.Content = paths.Count;
            }

            LineGrid.Children.Clear();
            LineGrid.Width  = _gridWidth;
            LineGrid.Height = _gridHeight;
            LineGrid.Children.AddRange(_interpLines);
            CanvasScroller.Visibility = Visibility.Hidden;
            ImageDisplay.Source       = BitmapToImageSource(CreateTransparentBitmap(_loadedImage.Width + 1, _loadedImage.Height + 1));
        }