[need help] Tracing raster-to-vector process

No algorithm is perfect or satisfactory.

Have you tried changing the settings in “Options”, or turning off “Smooth” or “Stack scans”? I find that tweaking these switches and values yield very different results. A small change or a different combination can go a long way, and it isn’t as simple as increasing an effect – the visual change isn’t linear or predictable in my experience. It will take a lot of time to get it just right, as Goldilocks would have it.

Even then, you may have to do some heavy editing in Inkscape to get things to fit your standards.

Turning off stack scans gives accurate colours but …there are transparent holes here and there :frowning:

Here’s without stack scans.

Not sure why the colours lean so much toward yellow/orange in stack scans mode :frowning:

Alrighty …so I believe that I am one step closet to solving this mistery.
With stack scans, the result was dark and yellow, without, it was light and colourful (but with random transparencies).

This is what I got by having them superimposed: stack scans on the bottom and the without on top, then lined up.

It’s 2:55AM and I’m tired …I’ll review this more tomorrow but I think I may be on the right track …over and out :slight_smile:

Heck, I’m feeling so accomplished that if this works out I’ll make a tutorial out of it and share the vector with y’all. Not that you care for it :stuck_out_tongue:

1 Like

I’ve investigated this subject quite a lot personally. Here are some things I can tell you:

  • Don’t bother turning off stack scans, generally. Always creates transparency and there is no easy good looking fix.
  • Autotrace is pretty much uniformly worse quality than PoTrace (the algorithm built into inkscape).
  • The ‘Colors’ and ‘Grays’ choices both indexize the image to N colors. You can do an end-run around this by indexizing it in advance (eg in GIMP) to N colors, and verifying the colors are satisfactory.
  • Lots of traces == slow (both to trace and to render) and big filesize. I never solved this to my satisfaction. Your ‘stack both versions’ solution is even more scary in these terms :wink:
  • ‘Smooth’ checkbox == gaussian blurring. Never found this good to use, personally, it rounds corners off too much.
  • The main parameter to adjust is the ‘Smooth corners’ threshold. You can think of this as how willing the trace will be to abstract away details of your shapes. Judging from your complaints, you might be happier with a lower threshold (eg. 0.6). The man page says “The smaller this value, the more sharp corners will be produced. If this parameter is 0, then no smoothing will be performed and the output is a polygon. If this parameter is greater than 4/3, then all corners are suppressed and the output is completely smooth.”
  • I never noticed any color difference with or without stack scans – that sounds like a bug. Did you check the opacity of the paths generated with Stack Scans on?
1 Like

Yes, as I wrote:


I don’t think it is a bug per se but how the paths and nodes are drawn.

  • The reason that there is transparency when “Stack scans” is off is that the algorithm’s focus is to preserve shapes (“tiling” as Inkscape calls it; think of a tiled floor or stained-glass window). Unfortunately, path edges don’t line up perfectly (hence introducing transparency) but the colors tend to be more accurate due to the segmentation.

  • In contrast, when “Stack scans” is on, the algorithm takes the approach of a painter. Each scan is like another layer to the painting (“stacking” as Inkscape calls it; watch an episode of Bob Ross’ The Joy of Painting :smile:). As there are less nodes and paths, the overlapping of shape boundaries occur. Those shapes don’t have to be object-based.

I haven’t used the trace tools in eons but these observations can be easily made by:

  1. Hovering over the options and reading the tooltips.
  2. Ungrouping or breaking apart objects and shapes and moving them around.
  3. Selecting the node tool to reveal and manipulate the nodes and paths.

@stefan.chirila, all the best but remember to keep it simple.

@D_Gowers could you download the image (the sample I posted above) and see if you get a difference in colour between with and without stack? I’d love to know if this is just my version or generic for the colours in this image.

It is a big file and would likely be slow, so if you don’t want to I’ll understand :slight_smile:

If indeed it is a generic thing that happens, then it would be nice if future versions had an option where it would create the with stacks and the without stacks and superimpose them for ideal quality :wink:

Hope someone who’s involved in development of it reads this :smiley:

@afre the image is big and moving layers around is slow, especially when scanning at something like 200 scans. That being said, though, perhaps the removal of one of the yellow/orange layers may help? Though I still don’t quite understand how the colours could be so strongly affected if scanning without overlap yields accurate results. Weird.

I want to thank you though for all the time you took replying. I really appreciate it! :smiley:

No color difference. It looks like there is if I leave it overlapped with original image, but if I pull the traced image away from the original bitmap first, comparison in an image viewer shows no color difference (only more holes in the unstacked version)

Why not just put a white layer the size of the canvas behind the image?

Yes, I mentioned that at one point.

I think the key is to understand what the intended purpose is for vectorization. At the moment, it appears that Stefan wants to duplicate his raster images to such accuracy that I wonder why not just use the original raster.

@D_Gowers when you apply a stack scan, do you not get this?

Left being the traced vector stack, and right being the original raster image.

As for Inkscape version, I had 0.91 …I upgraded just now to 9.2 but still same effect.

@afre the reason I want a vector is because I enjoy the look and feel of them. But no offense …if you look at the colours I got, and how yellow the trace ended up compared to the rich reds and greens in the raster, I really don’t think I am demanding the moon and the stars here :stuck_out_tongue: I don’t see why it didn’t reproduce them properly in this mode when without stack scans it does …with annoying transparent spots.

Because the transparent spots do not show up where where is missing and it looks awkward and a bit overly light. A black layer does a better job yet darker than should. I’ll do a tutorial on the method I found solves it.

No offense taken. I was just wondering if vectorization is the best solution. An open question: maybe it is or maybe it isn’t. I mean you could get a similar look by manipulating a raster, unless you are willing to go deeper than simple tracing.

As for color shift, I do see the problem and empathize. However, I am not good with colors. I can see the difference between colors but somehow have trouble identifying them, so I have refrained from commenting on the subject.

If the color shift is regional, you could attempt to place shapes on top of the trace to blend and reach your target color. I have done this in the past when in a bind. There are many online tools that can help find the hexes you need.

Well here’s the “tutorial.” Looks like this is about as good as can be done in the current situation. Hope it’s helpful to anyone. I’d like to help you all for helping and joining the group effort :slight_smile:

Click Here for better quality version.

1 Like

… Well, the colors aren’t the exact same as in the raster version, if that’s what you mean (though I wouldn’t say they are quite as different as your picture shows… only a little dimmer than the original, which is a typical side effect of quantization).

However, the colors in a trace with the Stack option on are completely identical to the ones in a trace with the Stack option off – ie. the Stack Scans option does not affect colors at all. I can post a comparison if you want.

Checking up on this reminded me that the Preview pane in the Trace dialog should show exactly what colors you are gonna get, since it displays a thumbnail of the ‘preprocessed’ image (in this case, the image after it has been quantized to N colors). It’s interesting to note that in all frames of your tutorial the thumbnail shown has the reddish tone.

FWIW I’m running inkscape bzr r15625 (ie. trunk, which will eventually become release 0.93)

EDIT: I think I was tracing a different image than you meant though, I’ll retry.

Second try (originally I traced the OP image with your logo etc, now traced the correct tree image):

I see the traced result is displayed yellowish.
This is the actual bug.
The traced result is not yellow when exported!

Traced result as shown in gimp, inkscape, and sxiv

I’m not sure exactly what the cause of this bug is, but it seems pretty clear to me now it is an issue with Inkscape’s display.

1 Like

@D_Gowers so when you trace it with stack option on in inkscape, the result shows yellow like mine …but after you save the vector and open it in gimp it renders correctly? interesting. I haven’t tried saving it and rendering it, I assumed inkscape would display it right. I will try this at home tonight.

What I’m wondering now is …if one were to exit inkscape then restart it and open the saved vector, would it still show yellow or render right? If you can check before I get home please let me know, otherwise I’ll post results tonight. My version at first was 0.91 but last night I updated to 0.92, no difference in rendering though.

I took another look at the problem at different angles. My computer is incredibly under-powered – likely more so than yours, so there was a lot of waiting for the CPU/GPU to catch up and screen to refresh.

I tried saving the SVG and opening it again. I get

I also tried exporting the bitmap and traced object, respectively, using “Export PNG Image”. Takeaways:

  • On my system, exporting doesn’t remove the color shift. Since I don’t trust my eyes, I used a global system color picker to verify. Note the overlaid purple rectangle: I measured the top-left and bottom-right patches inside, comparing raster and vector in app and their exported versions.

  • The color shift isn’t uniform, which makes me suspect that it has to do with issues related to not only posterization but color conversion and management.

  • As @D_Gowers mentioned, Inkscape’s trace tool is based on Potrace. Have you tried using the tool directly? As-is, I don’t believe that Potrace is meant to trace color images.

I forgot to mention how I would deal with the transparency problem. Below is a quick and dirty method. There is some smoothing/dilation, but in my opinion it is an acceptable trade-off for increased color accuracy.

  • Select trace
  • Object > Ungroup
  • Path > Outset
  • You may tweak this by using. Preferences > Behavior > Steps

Outset paths by 1px:

PS To make the features less rounded, maybe outset a bit larger than 1px, then inset back to 1px. Again, my computer is super old, so I will let you try it.

1 Like

thanks for this! good technique to know!