[SOLVED] How do I replicate Inkscape's bitmap tracer?

General discussions about Inkscape.
Buy Fifty Shades of Grey

[SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby ukurereh » Sat Apr 14, 2012 2:06 pm

.
Edit: I made a script to do this from the command line, see post #9.

I want to do command-line or scripted bitmap tracing, but Inkscape's tracer can't be automated. Potrace only does black-and-white images, so there must be a lot more going on under the hood with Inkscape.

So if I were to instead use Potrace (and probably ImageMagick, and some SVG tool?), how would I replicate Inkscape's functionality with color, multiple scans, and stacking scans?
Last edited by ukurereh on Mon May 21, 2012 3:41 pm, edited 4 times in total.
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: How do I replicate Inkscape's bitmap tracer with Potrace

Postby brynn » Sat Apr 14, 2012 6:03 pm

Potrace only does black and white? I had the impression that potrace and Trace Bitmap were basically the same thing. The technical side of Inkscape is definitely not my forte though, lol.

You could check out the developers' mailing list, and/or irc channel. I think that not many developers participate here. So if you don't get an answer, you could try those places where they hang out and communicate :D
Basics:
> Help menu > Tutorials
> a Quick Guide to Inkscape
Manual:
> Inkscape: Guide to a Vector Drawing Program
Tutorials:
> Inkscape Community
Development news
> Google+
Gallery:
> Inkscape Community Gallery
User avatar
brynn
 
Posts: 6759
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA

Re: How do I replicate Inkscape's bitmap tracer with Potrace

Postby tomh » Sun Apr 15, 2012 1:22 am

Not an expert, but...

Potrace only does black and white? I had the impression that potrace and Trace Bitmap were basically the same thing.


Potrace only does black and white. Inkscape has added several pre-processing steps that enable it to do the fancy traces, basically doing the colour prossessing steps and passing black and white images for potrace to scan.

The code is here: http://bazaar.launchpad.net/~inkscape.d ... src/trace/
Might not be that helpful but might give you some idea of what inkscape is doing (even if you only read the titles and comments in each file and match them to the trace bitmap dialogue.

Basically it makes very clever use of pre-processing.

For example the colour scan option uses colour quantisation: http://www.imagemagick.org/Usage/quantize/ to reduce the number of colours; then extracts only one of those colours and uses a threshold operator to convert the image into black and white. It then passes that to potrace to scan and then combines the results back together.
User avatar
tomh
 
Posts: 218
Joined: Sat Feb 14, 2009 10:14 pm

Re: How do I replicate Inkscape's bitmap tracer with Potrace

Postby ukurereh » Sat Apr 21, 2012 10:51 am

Here it is, a Python script to trace a whole directory of color images at once.
- You need to install Python 3.2 or later, and also the lxml library for that version of Python.
- Unless you get the Windows version, you'll also need to download potrace, pngnq, and ImageMagick.
- Then you need to add those programs' directories to your PATH variable so they can be accessed directly from the command line. (Or if you don't want to do that, you can edit the executable paths near the top of color_trace.py)
- Once you've got all that, run color_trace.py from the command line using Python 3.2.

Source & external programs (i.e. Potrace and such already included):
color_trace-win-0.02.zip

Source only (other platforms, must download external programs):
color_trace-0.02.zip
(10.66 KiB) Downloaded 184 times
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby ukurereh » Mon Apr 23, 2012 2:03 am

Bump. Here are some pictures traced with 256 colors. They took hours each, nearly overheated my laptop, and made svg files about 20 megs each. So don't trace 256 colors unless you're feeling adventurous, m'kay?

Image

Image
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby brynn » Mon Apr 23, 2012 5:37 am

Well that's awesome! Those are vector images?? Because that's better than what Trace Bitmap can do, in my experience!

If you like you can post a new topic in Inkscape Resources subforum, with links to the file, etc. Then people can find it quickly, and also ask related questions in that topic.

Or I could move this one for you? Let me know :D
Basics:
> Help menu > Tutorials
> a Quick Guide to Inkscape
Manual:
> Inkscape: Guide to a Vector Drawing Program
Tutorials:
> Inkscape Community
Development news
> Google+
Gallery:
> Inkscape Community Gallery
User avatar
brynn
 
Posts: 6759
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA

Re: How do I replicate Inkscape's bitmap tracer with Potrace

Postby ~suv » Mon Apr 23, 2012 1:26 pm

ukurereh wrote:Here it is, a Python script to trace a whole directory of color images at once.
- You need to install Python 3.2 or later, and also the lxml library for that version of Python.
(…)

You won't offer a version compatible with Python 2.7? I would have been interested in testing the script on OS X 10.7.2 - even wrote a MacPorts portfile for pngnq - only to realize later-on that it would force me to install a (potientally conflicting) Python version.

(Note: Inkscape's extensions haven't been migrated to fully support Python 3.x - whoever (on linux) [1] changes the system-wide default python version to 3 without taking care that Inkscape still spawns python-2.x for the bundled extensions, might have issues with failing extensions (input/output as well as effects)).


[1] Edit: I don't know what happens to Inkscape users on Windows who redefine the global %PATH% variable to point to a system-wide custom Python 3.x installation (AFAIK untested with Inkscape 0.48.x, which includes its own python 2.6.5 executable as well as the modules lxml 2.2.4 and numpy 1.4.1).
~suv
 
Posts: 1955
Joined: Sun May 10, 2009 2:07 am

Re: How do I replicate Inkscape's bitmap tracer with Potrace

Postby ukurereh » Thu Apr 26, 2012 7:21 am

~suv wrote:You won't offer a version compatible with Python 2.7?

I can do that, just give me the next day or so.

BTW this has nothing to do with Inkscape's extensions. And doesn't Inkscape use its own installation of Python? (or maybe that's just on Windows)

Edit: I'm sorry, real life is getting in the way >_<

Edit edit: I'm just going to forget doing a Python 2.7 backport and instead focus on making standalone executables that don't require Python at all.
Last edited by ukurereh on Mon May 28, 2012 1:06 pm, edited 2 times in total.
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby ukurereh » Mon May 21, 2012 3:37 pm

Version 1.00a is out! This program uses potrace to trace color images.
This version runs faster, has more color quantization options (median-cut, adaptive spatial subdivision, and neuquant), supports dithering*, prescales the image for better quality, makes available several of potrace's options, and can use an external palette instead of color quantizing.
*Dithering will make the output svg much larger and more complex, and may or may not produce desired results.


Now in executable form, with no need to install Python and such! (Windows only for now, Mac version in the future)
Windows executable & external programs (i.e. Potrace and such already included):
color_trace_multi-win32-exe-1.00a.zip
- You might need to install the Microsoft Visual C++ 2008 Redistributable Package (free download, for x86 (32 bit) Windows or for x64 (64 bit) Windows).

And then...
- Once you've got that, run color_trace.exe from the command line.
- Use the switch -h or /? for help, or read the README.txt.

---------------------------------------------------

Requirements for source versions:
- You need to install Python 3.2 or later, and also the lxml library for that version of Python.
- To use this program, you will need to know how to use the command line/shell.

This next part is unnecessary if you get the Windows version.
- Unless you get the Windows version, you'll also need to download potrace, pngquant, pngnq, and ImageMagick.
- Then you need to add those programs' directories to your PATH variable so they can be accessed directly from the command line. (Or if you don't want to do that, you can edit the executable paths near the top of color_trace_multi.py)

And then...
- Once you've got all that, run color_trace.py from the command line using Python 3.2.
- Use the switch -h or /? for help, or read the README.txt.

Windows version with source & external programs (i.e. Potrace and such already included):
color_trace_multi-win32-1.00a.zip

Source only (other platforms, must download external programs):
color_trace_multi-1.00.zip
(23.61 KiB) Downloaded 219 times


Edit: :oops: Oops, it gives a very unhelpful error message when a file is missing, I will fix that in the next release. Also, -s/--stack will be the default and be disabled by --nostack. Coming soon! (But not that soon because I will be out of state.)
Last edited by ukurereh on Mon May 28, 2012 1:43 pm, edited 2 times in total.
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby ukurereh » Mon May 28, 2012 1:24 pm

Bump for Windows executable release and slight bugfix (1.00a). See the above post for more information.

Note: I think I'll eventually re-post this in the Inkscape Resources subforum (as suggested in brynn's post which I totally missed :| ), once I get a new version and Mac executable out.

And also: Can anyone think of a better, catchier name for this program?
- I considered "rainbowtrace", but it's already taken by a Japanese band or something. Could I still use it?
- And "rainbowtracer" is an LED project of some sort.
- And of course "colortrace" is taken by half a dozen things at least.
- Huh, maybe "rainbotrace" (as in rainbow+potrace), but that's prone to misspelling... how about "rainpotrace"?
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby Lars_Bylund » Tue May 29, 2012 11:45 pm

I know that this is a solved one, and I havent really read every post, but anyway.

I use :

for i in *.png; do autotrace "$i" -despeckle-level 14 --output-file "$(echo $i | sed 's/.png/.svg/')"; done

in the map with my (png) pictures.

I used this as an 'effect' on a video you can see here (please view in full hd!)
http://www.youtube.com/watch?v=R8zW2MHhgUE

This is how it's done, even if it's a bit of topic.

I first convert avi to pngs:

ffmpeg -i fro.avi image%d.png

png's to svg:

for i in *.png; do autotrace "$i" -despeckle-level 14 --output-file "$(echo $i | sed 's/.png/.svg/')"; done

svg to png:

for i in *; do rsvg-convert $i -o `echo $i | sed -e 's/svg$/png/'`; done

and png to avi:

ffmpeg -i image%d.png -vcodec huffyuv test.avi
Lars_Bylund
 
Posts: 7
Joined: Mon Nov 28, 2011 9:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby ukurereh » Sun Jun 03, 2012 6:30 am

Hey Lars, much thanks for your bash(?)+autotrace solution.

To anyone who can't get the win32 version of color_trace_multi to work, it's not your fault (ImageMagick giving an error about unsupported decoder/codec or whatnot) because apparently I forgot to include some important files. A quickfix is to install ImageMagick and then copy the installed files over to the included "bin\imagemagick-q8" folder.
User avatar
ukurereh
 
Posts: 10
Joined: Sat Apr 14, 2012 11:35 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby mike_ » Mon Jul 16, 2012 8:58 pm

Hi ukurereh,

thank you for developing the color trace tool. I've tried it, but unfortunately I ran into a problem.

When I try to run the tool with the command :
Code: Select all
c:\temp\color_trace>color_trace_multi.exe -i 4208.png -c 16 -d C:\temp --output temp.png

I get the following error :
[Errno 2] No such file or directory: 'C:\\temp\\temp~tmp_scaled.png'

I have tried to run ImageMagick's `convert` tool from the command line and it works, since I had the other version (6.7.8) already installed in my Program Files. I don't have the PATH variable setup to the color_trace/bin sub-directories.
I wanted to try to fix the problem, but I'm new to Python and after installing Python 3.2 and running your script it complains it cannot find the `svg_stack` module.

I get the same problem on two separate machines, one is running 32bit and other one is 64bit Windows 7 Enter&prise ;)

Can you please help me with this issue ?

Thank you.

//edit: Apparently I've missed the post above. I've replaced the bundled IM with fresh install and it worked like charm. My bad, sorry about that. :roll:
//The results weren't correct, because the colors and shapes were different from one's in the Inkscape and looked worse.
mike_
 
Posts: 1
Joined: Mon Jul 16, 2012 8:47 pm

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby webkopejka » Sat Aug 18, 2012 2:28 am

Hello.
I tried to run
python color_trace_multi.py -i 1.png -o 1.svg -c 16
but get a message "'module' object has no attribute 'SW_HIDE'"
Using ubuntu 12.04 + python3.2

No new files created.
Can you help me run the script correctly, please?
webkopejka
 
Posts: 2
Joined: Sat Aug 18, 2012 2:21 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby webkopejka » Sat Aug 18, 2012 3:11 am

Hello.

Now I try to run:
sudo python color_trace_multi.py -i './1.png' -o './1.svg' -c 16 -q nq -v

and output is:

"convert" "./1.png" -filter lanczos -resize 200% "./1~tmp_scaled.png"
"pngnq" -f -d "." -n 16 -e ~quant.png "./1~tmp_scaled.png"
"convert" "./1~tmp_reduced.png" -unique-colors -compress none ppm:-
"identify" -ping -format "%w" "./1.png"
"convert" - -fill #000001 -opaque "#999a9e" -fill #ffffff -opaque "#898679" -fill #ffffff -opaque "#000000" -fill #ffffff -opaque "#f2e5dd" -fill #ffffff -opaque "#8f8557" -fill #ffffff -opaque "#f9f500" -fill #ffffff -opaque "#f7f000" -fill #ffffff -opaque "#ccb100" -fill #ffffff -opaque "#bea938" -fill #ffffff -opaque "#992026" -fill #ffffff -opaque "#0b0a0a" -fill #ffffff -opaque "#080706" -
"convert" - -fill #FFFFFF -opaque "#ffffff" -fill #000000 -opaque #000001 "./1~tmp_layer.ppm"
"potrace" --svg -o "./1~tmp_trace.svg" -C "#999a9e" -t 2 -a 1.0 -O 0.2 -W 3.422222222222222 "./1~tmp_layer.ppm"
Document is empty, line 1, column 1

In the end I can see a file "-fill" and it is not vectorized.

Can anybody help me to vectorize something?
Thank you a lot :)
webkopejka
 
Posts: 2
Joined: Sat Aug 18, 2012 2:21 am

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby hellocatfood » Fri Sep 07, 2012 8:18 pm

I tried to run version 1.0 on Ubntu 12.04 using this code

Code: Select all
python color_trace_multi.py -i /home/hellocatfood/Desktop/color_trace_multi-1.00/ -o /home/hellocatfood/ -c 10


and I got this error, with no output

Code: Select all
  File "color_trace_multi.py", line 47
    def verbose(*args, level=1):
                           ^
SyntaxError: invalid syntax
I'm on The Web | Flickr | tumblr
User avatar
hellocatfood
 
Posts: 171
Joined: Fri Aug 29, 2008 8:49 pm

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby abhasbaghel » Wed Feb 26, 2014 3:41 pm

hellocatfood wrote:I tried to run version 1.0 on Ubntu 12.04 using this code

Code: Select all
python color_trace_multi.py -i /home/hellocatfood/Desktop/color_trace_multi-1.00/ -o /home/hellocatfood/ -c 10


and I got this error, with no output

Code: Select all
  File "color_trace_multi.py", line 47
    def verbose(*args, level=1):
                           ^
SyntaxError: invalid syntax


Hello hellocatfood,

I am also facing same problem. Please tell me if you have solved this. I used windows version as well as linux but on both plateform I faced some problems. I have to create raster to svg . So I request to all please help me ASAP. :cry: :cry: :cry: :cry:
abhasbaghel
 
Posts: 1
Joined: Wed Jan 29, 2014 7:46 pm

Re: [SOLVED] How do I replicate Inkscape's bitmap tracer?

Postby hellocatfood » Wed Feb 26, 2014 6:48 pm

Nope, I didn't find a solution
I'm on The Web | Flickr | tumblr
User avatar
hellocatfood
 
Posts: 171
Joined: Fri Aug 29, 2008 8:49 pm


Return to General Discussions

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest