Inkscape + Python = vectorize???

Post questions on how to use or achieve an effect in Inkscape.
Perfect_Chaos
Posts: 5
Joined: Thu Jun 25, 2009 8:19 pm

Inkscape + Python = vectorize???

Postby Perfect_Chaos » Thu Jun 25, 2009 8:28 pm

Hi folks!
I'm currently writing an report about automatic vectorization of bitmap streetmaps into a vector format so that every single street (highway, road, river) which has its own color becomes a vector of that color.

I chose Inkscape because it has a goof color vectorization.

Now I heard that you can use Python scripts in Inkscape. My question is if I can use Inkscape commands with Python (open files, vectorize bitmaps [like VBA does with Microsoft Excel]).

If it is possible it would be nice if somebody could tell me where I can get a list of Inkscape commands in Python (like file.open() or vectorize() ). Commands for opening files and to trigger the vectorization with different settings i need the most.

Thx very much!

Perfect_Chaos
Posts: 5
Joined: Thu Jun 25, 2009 8:19 pm

Re: Inkscape + Python = vectorize???

Postby Perfect_Chaos » Sun Jun 28, 2009 4:45 am

Sorry for being so rude and double post just to push this thread back to the top but its very important for me.

Does nobody know a trick how to control the open dialog, bitmap vectorization and save dialog via command promts or Python (or other programming languages)?

Simarilius
Posts: 626
Joined: Wed Jun 06, 2007 2:37 am

Re: Inkscape + Python = vectorize???

Postby Simarilius » Sun Jun 28, 2009 4:51 am

The vecotrization in inkscape is being done using potrace, which is available as a standalone command line app which may be of more use to you.

http://potrace.sourceforge.net/

Not sure if you can script the vectorization in inkscape itself, but potrace will kick out svgs.

Perfect_Chaos
Posts: 5
Joined: Thu Jun 25, 2009 8:19 pm

Re: Inkscape + Python = vectorize???

Postby Perfect_Chaos » Mon Jun 29, 2009 7:47 pm

Yeah ok thanks but I already found this out. The Problem with potrace is that it only can vectorize in black & white. Inkscape splits the picture in color channels before it vectorizes them with potrace. Then they are merged together and make a vectorized color picture.

When I need to program the color vectorization with potrace i'll even not be finished at chrsitmas time ^^

There must be a way to trigger at least the open dialog, the vectoritaion and a save dialog automatically. I think I dont need more functions of Inkscape.

User avatar
seeminglee
Posts: 6
Joined: Sun Jun 21, 2009 8:24 pm
Location: New York City
Contact:

Re: Inkscape + Python = vectorize???

Postby seeminglee » Fri Jul 03, 2009 1:40 pm

fyi, I've been trying to do exactly what you're after and I thought that I'd share another approach for you to potrace multi-color image:

I came across this awesome tutorial for vectoring images from an uber-geek's website:
Automatic Generation of Stained Glass from Scanned Photos by C. Scott Ananian
http://cscott.net/Projects/Mallard/

I'd assume that you're looking to process continuous-toned images so you might want to first write a script to pre-process the image by posterizing the colors in GIMP.

As per how to do this via script only within Inkscape, I don't really have a good suggestion for you as aside from the verb for showing the trace dialog, I haven't been able to find the equivalent verb in /inkscape/src/verbs.cpp for the actual tracing operation, and so I would assume that it might not be possible... That said, you might also wish to check out Inkscape source C++ source code to figure out how they do it by looking into the source for the tracing section which is inside /inkscape/src/trace/

/SML

Perfect_Chaos
Posts: 5
Joined: Thu Jun 25, 2009 8:19 pm

Re: Inkscape + Python = vectorize???

Postby Perfect_Chaos » Sun Jul 05, 2009 5:12 pm

Thank you seeminglee!

The Tutorial is far too complicated for the simple function I want to realise. I have 9 weeks time to write a 30 pages report about my project. And the automatic vectorization is just one half of the projekt ^^

But Iam goning to look at the C++ source of Inkscape.

But what use has the Python interface when I cannot control Inkscape functions with it?

Simarilius
Posts: 626
Joined: Wed Jun 06, 2007 2:37 am

Re: Inkscape + Python = vectorize???

Postby Simarilius » Tue Jul 07, 2009 6:58 am

Bob Jamison wrote most of the potrace support, hes a pretty busy guy but very helpful.
you can sometimes catch him in the jabber room, his nick is ishmal.

trace dialog is in src\ui\dialog\tracedialog.cpp if you want to look at it.

Perfect_Chaos
Posts: 5
Joined: Thu Jun 25, 2009 8:19 pm

Re: Inkscape + Python = vectorize???

Postby Perfect_Chaos » Mon Jul 20, 2009 3:50 pm

One last try if somebody found a solution for my problem or can help me in any way.

My problem is still that I want to find a script for Inkscape that opens 2 BMP pictures (via automaticaly triggered Open-Dialog), that then automatically vectorizes the pictures with given parameters and then saves the images as .svg

My first thought was that I use the python port of inkscape but I heard that I cannot trigger Inkscape commands through this (what I still find very strange).

My second plan is to use autotrace under Linux to do the vectorization but my original task is to do it with Inkscape, which is why I ask here again.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Inkscape + Python = vectorize???

Postby ~suv » Mon Jul 20, 2009 8:23 pm

  • Inkscape Wiki: Category:Extensions
  • Inkscape » Using the Command Line
  • Inkscape command line options (Hilfe > Kommandozeilen-Optionen)
    --verb-list

    Lists all the verbs that are available in Inkscape by ID. This ID can be used in defining keymaps or menus. It can also be used with the --verb command line option.

    --verb=VERB-ID, --select=OBJECT-ID

    These two options work together to provide some basic scripting for Inkscape from the command line. They both can occur as many times as needed on the command line and are executed in order on every document that is specified.

    The --verb command will execute a specific verb as if it was called from a menu or button. Dialogs will appear if that is part of the verb. To get a list of the verb IDs available, use the --verb-list command line option.

    The --select command will cause objects that have the ID specified to be selected. This allows various verbs to act upon them. To remove all the selections use --verb=EditDeselect. The object IDs available are dependent on the document specified to load.
  • share/keys/default.xml
    This file contains the default Inkscape keyboard shortcuts. In each "bind" element:
    <…>
    - The "action" attribute contains the name of the action. The complete list of actions
    (called "verbs") is in the file src/verbs.cpp in Inkscape source; there you can see
    brief descriptions of what each action does. The same action may have multiple key
    bindings.
    <…>
    <bind key="b" modifiers="Alt,Shift" action="SelectionTrace" display="true"/>
    <bind key="B" modifiers="Alt,Shift" action="SelectionTrace" />
  • src/verbs.cpp, src/verbs.h
    * \file verbs.cpp
    *
    * \brief Actions for inkscape
    *
    * This file implements routines necessary to deal with verbs. A verb
    * is a numeric identifier used to retrieve standard SPActions for particular
    * views.
hth, ~suv

CarlCravens
Posts: 26
Joined: Wed May 27, 2009 7:32 am

Re: Inkscape + Python = vectorize???

Postby CarlCravens » Tue Jul 21, 2009 3:58 am

Perfect_Chaos wrote:My second plan is to use autotrace under Linux to do the vectorization but my original task is to do it with Inkscape, which is why I ask here again.


Inkscape isn't the right tool for this job. It would be convenient if you could automate this with Inkscape, but that functionality isn't there. This is kind of like trying to use an automobile to generate electricity from gasoline... yes, you can do it if you go to the trouble, but if all you want is electricity from gasoline, use the generator that's already in your shed.

Here's a tutorial on how to use potrace and a handful of other Linux command-line tools to process a color image in the same way Inkscape does (with improvements over Inkscape's method, according to the author)...

http://confluence.concord.org/display/C ... lor+Layers


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: No registered users and 10 guests