0

I have png-images of a grayscale circle and background alpha enter image description here

I would like to extract the 50% contour (only the diagonal line) and export it as a path into an svg-image. Until now I tried to do this with ImageMagick and Potrace, but I was not able to get the desired result:

  1. The following command gives me the complete area, but not the border. After opening it in Inkskape I can by hand make the contour transparent and add a color to the border and maybe afterwards also delete the parts of the circle which I don't want to have. But I would rather have something which runs automatically.

    convert input.png -threshold 50% pgm:- | potrace - --svg --invert > result.svg

  2. I can extract only the border first with ImageMagick, but also a part of the circle. I think I would be able to maybe put a mask on the result to delete the circle again, but then if I try to use potrace to generate an svg-image, I can only get a shape of the form of the contour, but not a path.

    convert input.png -threshold 50% -edge 1 pgm:- | potrace - --svg --invert > result.svg

Maybe there is a completely different way to achieve what I want to have. It would be nice to do this by standard tools from the command line and not by hand or by writing a script to do it completely from scratch.

Paul Stahr
  • 41
  • 6

1 Answers1

1

Here is how to extract your 50% line in Imagemagick. (To convert to SVG, see https://imagemagick.org/Usage/draw/#svg_output)

enter image description here

convert circle.png -fuzz 1% -fill red -opaque "gray(50%)" -fuzz 0  -fill black +opaque red -fill white -opaque red -alpha off result.png

enter image description here

If you want just the coordinates, then in Unix syntax

convert circle.png -fuzz 1% -fill red -opaque "gray(50%)" -fuzz 0  -fill black +opaque red -fill white -opaque red -alpha off txt: | sed 's/^\(.*\):.*$/\1/g' | tail -n +2

You may want to reduce the fuzz value to get a narrower line.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • Thanks, that solves at least already the first step. – Paul Stahr Sep 16 '22 at 20:50
  • See my note at the top of my answer about converting to SVG. Sorry, I cannot help more on that. – fmw42 Sep 16 '22 at 22:21
  • Thanks for the help. The link was very useful in the end actually. Here my final solution: autotrace -input-format pgm -centerline -output-format svg <(convert circle.png -threshold 50% -background gray -alpha remove -morphology EdgeIn Diamond -negate -threshold 25% pgm:-) > out.svg – Paul Stahr Sep 21 '22 at 14:15