0

I am trying to Convert an Image to a PathGeometry. I upload a picture, and then I do canny edge detection and now I want to convert that in to a PathGeometry. My over all plan it to fill it with different colors.

So I tried this :`public Shape MakeSape(Brush customColor, double[,] image) { Path graphPath = new Path();

        graphPath.Fill = customColor;
        graphPath.Stroke = Brushes.Black;
        PathFigure pf = new PathFigure();
        pf.StartPoint = new Point(0, 0);
        pf.IsClosed = true;
        int row = image.GetLength(0);
        int column = image.GetLength(1);

        for (int y = 0; y < row; y++)
        {
            for (int x = 0; x < column; x++)
            {
                if (image[y, x] >= LowThreshold)
                {
                    pf.Segments.Add(new LineSegment(new Point(x, y), true));
                }
            }

        }

        PathGeometry pg = new PathGeometry();
        pg.Figures.Add(pf);
        graphPath.Data = pg;

        ImageAsShape = graphPath;
        return graphPath;
    }` 

And that looked like it should work, but I am just getting all black.

  • You seem to just draw a horizontal line from the left most point where the element is higher than the threshold to the right most point for each row and repeat it from top to bottom connecting the right most point of upper row and the left most point of lower row. Of cource the final outcome depends on the 2-dimentional array, but can you expect it produces a meaningful shape? – emoacht Mar 10 '22 at 21:11
  • I am not sure how to do it . But I want to convert a Picture into a path. Do you know how to do this? – MiltaruyOne Mar 11 '22 at 04:35
  • I am not familiar with this. Maybe connecting the nearest points one after another? – emoacht Mar 11 '22 at 05:55

0 Answers0