jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.
The Unlicense
1.31k stars 171 forks source link

artifact paths with opacity=0 #62

Closed chrisyelf closed 1 year ago

chrisyelf commented 1 year ago

Hi,

Thanks so much for this library!

I'm trying to parse the attached png

bee

I've found these options work great to remove noise:

scale 1 numberofcolors 8 ltres 1 qtres 1 pathomit 128

but there are still a few artifact paths with opacity=0 and color white. I've changed opacity to 1 and colors, so they are visible:

bee-it-obj

Is there a way to avoid generating these paths? I'm not sure why paths with opacity=0 would be useful to be included.

Thanks again and Happy New Year :)

jankovicsandras commented 1 year ago

Hi,

You're right, it's not really useful. But imagetracerjs treats transparency as a color, so it's rendered. (Might be useful if somebody would postprocess the SVG?) Anyway, you can try to insert this line

if( tracedata.palette[lcnt].a === 0 ){ continue; }

between lines 990 - 991 to omit opacity="0" paths.

Please let me know if this works, I haven't tested it. :) Happy New Year!

chrisyelf commented 1 year ago

Thank you Andras, that did work!

It would be useful to have exclude transparency as an option.

Happy New Year! :)