jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Determining ltres and qtres

oortlieb opened this issue · comments

Is there an approximate rule of thumb for guessing "good" values for a specific workflow? It seems that, for the best results, these values must be scaled with the size of the incoming bitmaps.

For example, I've trial-and-errored my way to some reasonable looking values for specific sizes (2.5 ltres and qtres for a 512x image, 5 for 1024x -- 2.5, of course, is close to sqrt(5)).

Hi,

It depends on how much detail you need. If you need bigger, approximate shapes and need to ignore small pixel errors, then it's a good idea to set bigger ltres and qtres. If you need fine details, then the default 1 or maybe 0.5 are good values. Setting the linear treshold ltres to 0.1 will force most shapes to be curvy, and similarly, small qtres will force most shapes to be polygonal.

ltres and qtres are pixel distances squared.

There are some logical limits to ltres and qtres values:

Every raster shape's octagonal hull is split on every 2-direction-change. (Because 2 line segments can be approximated by a Q spline.) This means, that e. g. a raster circle's octagonal hull will be split to 4 parts. If we set extreme large values for ltres and qtres, then these will be approximated as lines and we'll get a square (but never a triangle), it's not possible to have less detail than the octagonal hull's 2-direction-parts.

Setting extremely small ltres and qtres will probably produce the octagonal hull, which is rarely required. (Every raster image can be trivially vectorized and rendered to SVG by saying that every pixel is an 1x1 size rectangle, but that sound a bit silly.)

The key is trying to discard as much detail as possible while still having an acceptable result.

You can reopen this Issue and attach some input images here if you need more advice.

More info:

Process overview