0

Is there a (free) software for fitting splines to line graphics?

For example, I would like to sketch something on my android tablet or scan sketch and then place some nodes at the shape, and afterward, the vector graphic program should fit the spline to the lines.
This can't be too hard to implement, but I didn't find programs with such a feature.

I am not looking for vectorization like potrace (and the corresponding Inkscape binding) does it, as it results in hard to work with shapes. I am looking for a program, which fits splines to drawn paths. I have no problem placing a few landmark points before the spline is fitted to the drawn path.


Example:

Input image:

A bitmap with a line drawing

My preparation:

The bitmap with a polygon drawn over it

The result with manual fitting:

The polygon deformed to a curve that better approximates the shape

My question is about automating the last step.

It's not dumb smoothing, but finding the spline which fits to the curve in the bitmap image and to just that curve (among others) that I pointed by clicking a poly-line.

16
  • Are you referring to auto-tracing? There are many apps capable of that.
    – Scott
    Dec 7 '20 at 19:50
  • @Scott I am not meaning vectorization like potrace (and the corresponding inkscape binding) does it, as it results in hard to work with shapes. I am explicitely looking for a program, which fits splines to drawn paths.
    – allo
    Dec 7 '20 at 20:04
  • Spline fitting isnt hard at all (after all splines are designed for fitting). In fact most vector and cad software do it, to a different degree. Most have a freform draw tool that gets fitted, still does not seem any more workable than what you reject. But the question is rather how do you want to inoput and fit.
    – joojaa
    Dec 7 '20 at 20:22
  • 1
    @joojaa - Depending on what the OP actually wants, there's a possibility that tools such as Illustrator's Curvature tool, or Inkscape's Spiro path effect might work.
    – Billy Kerr
    Dec 8 '20 at 13:14
  • 1
    I guess there's overlapping other curves. Otherwise you would use Inkscape's Centerline Autotrace (appeared in v1.0) which finds at least your example curve perfectly but would go astray if there were crossings. Right?
    – user287001
    Dec 9 '20 at 0:50
1

Thanks for posting the image. It makes everything much clearer now.

The way you are proposing to do this won't work. Neither Inkscape nor any vector graphics software that I know of has any way of detecting edges in raster images, other than with auto tracing. So, a different approach is required.

Use the Centreline option in Inkscape's Path > Trace Bitmap function.

It does exactly what you want, fully automatically, without the need to even draw the lines yourself. Obviously centreline tracing is not so useful for more complex designs, but for the example you posted, it's almost perfect.

Example: Original raster image is on left, resulting centreline trace in the middle, and the Trace bitmap options on the right.

enter image description here Click on image above to see larger

The only thing you may need to do manually is to increase the stroke width in the Fill and Stroke Panel (Shift+Ctrl+F) to match the raster image.

Inkscape also has a Simplify command if you think the trace has created too many nodes. Also if you want sharper corners you could select specific nodes and turn them into corner nodes, and make small adjustments to their positioning.

Another more manual approach in cases where Centreline tracing might fail is to use the Bézier Tool(aka Pen Tool) in Inkscape, and click and drag Bézier curves as you go. It will save time rather than trying to fit/adjust curves afterwards. Another possibility if you are not familiar with creating your own Bézier curves in this way is to use the Spiro option in the tool controls along the top to automate the curves. When using the latter option, holding down Shift while you click will add a corner node, while regular mouse clicks produce curve nodes.

8
  • Thank you, this is helpful. I still hope if there may be tools (it's a well-known optimization problem in science). I am not sure if my use-case (vectorizing anime style sketches) will work that easy. My previous tries with the vectorization tool did not work out very well. But I'll check what I can achieve using the method in your post.
    – allo
    Dec 9 '20 at 11:14
  • @allo this only works for rather simple shapes. For anything more complex, you'll need to learn how to use the Bézier tool properly. Clicking lines, then adjusting the curves later is not efficient.
    – Billy Kerr
    Dec 9 '20 at 11:18
  • @allo its not normal for scientists to do a piecevise fitting like you did but rather smooth fitting the problem is not at all that i can not fit. but rather whet heurestics would you use to determine the cusp and where to seatch the data from. So the problem is really 3 of the 2 bottommost points. Why on eart would any fitting algorithm fit them like that, what kind of function would minimize that way.
    – joojaa
    Dec 9 '20 at 12:40
  • @joojaa You are probably thinking about general curve fitting. That's another thing, but not useful for vector graphics. I am talking about optimization of splines (or other piecewise curves), which is a problem from the computer graphics part of computer science. Discussion related papers would be a topic for the compsci site. It is not too useful to discuss them here, as I don't want to implement it myself but am looking if there are some solutions which implemented such algorithms in a user-friendly way.
    – allo
    Dec 9 '20 at 13:00
  • @allo no im aware of this subject, i have optimizers like this in cartography and engineering software. But why would the optimizer make a cusp in the southwest most point of the curve. The data ios smooth enough to begin with what would prompt thw algorthm to make it that way?
    – joojaa
    Dec 9 '20 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.