0

Let's consider the simple following image in its SVG representation (running the code snippet will display it):

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="200" width="200">
  <g>
    <path d="m 90.200184,21.865233 13.886726,0 0,91.406257 q 0,8.4375 -4.306646,11.86524 -3.7793,2.72461 -13.35938,2.72461 -10.37109,0 -18.19336,-1.05469 l -2.46094,-13.53516 q 11.07422,2.02148 18.45704,2.02148 5.97656,0 5.97656,-5.97656 l 0,-87.451177 z"/>
  </g>
</svg>

The SVG path is actually a collection of points all around the shape, while it could be a simple top-down slanted curve (the red line here). Unfortunately, I am provided these images, and cannot change them.

I am looking for a way to convert—or rather approximate—the SVG polygon to an SVG open curve., either directly or in several steps.

Any solution is welcome, but my preference goes to this order:

  1. programmatically (so that I can script it);
  2. using Inkscape or GIMP (or any other Linux program);
  3. well, anything that would work.

Thanks,

2 Answers2

0

Isn't it as simple as deleting the closing z from the path?

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="200" width="200">
  <g>
    <path d="m 90.200184,21.865233 13.886726,0 0,91.406257 q 0,8.4375 -4.306646,11.86524 -3.7793,2.72461 -13.35938,2.72461 -10.37109,0 -18.19336,-1.05469 l -2.46094,-13.53516 q 11.07422,2.02148 18.45704,2.02148 5.97656,0 5.97656,-5.97656 l 0,-87.451177"/>
  </g>
</svg>

Or are you looking for something more complicated than that?

Obviously, deleting the closing z is simple to script in your programming language of choice.

Stephen Thomas
  • 13,843
  • 2
  • 32
  • 53
  • Not exactly, because I would still keep the outline around the shape instead of a line. Basically, what I want to get, is the red line on this picture: http://imgur.com/7kzi4Lp. –  May 14 '15 at 14:34
  • That's going to be difficult, if not practically impossible, for arbitrary paths. (Unless, of course, you're willing to delve into machine vision algorithms.) – Stephen Thomas May 14 '15 at 14:44
0

This class of algorithms is generally known as finding the "skeleton" or "medial axis". If you search on those terms you will find papers and other documents describing different potential approaches. Many/most usually involve starting with bitmaps though.

https://en.wikipedia.org/wiki/Topological_skeleton

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181