Swilena

From LRDE

Revision as of 15:04, 12 November 2014 by Bot (talk | contribs) (Don't include the menu if the page is used included in another page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)



Swilena the a SWIG-based scripting interface of the Olena platform. It currently features a Python interface to the Milena C++ library. Support for Ruby (as in Olena 0.11) is also planned.


Swilena/Python

Swilena/Python gives access to a subset of Milena through the Python programming language. Currently, only a few data structures and morphological algorithms are available; more wrappers will be released later.

The code written using Swilena/Python looks like a simplified version of the Milena equivalent C++ code (no type annotations, no template constructs, etc.). For instance, the following script performs a watershed-based segmentation.

 1import data
 2from swilena import *
 3
 4image = image2d_int_u8
 5
 6# Input.
 7ima = image.load("lena.pgm")
 8
 9# Gradient.
10gradient = image.gradient(ima, win_c4p())
11
12# Area closing of the gradient.
13closed_gradient = image.closing_area(ima, c4(), 50)
14
15# Watershed transform.
16nbasins = int_u8()
17ws = image.meyer_wst (closed_gradient, c4(), nbasins)
18
19# Output.
20print nbasins
21image.save(ws, "segm.pgm")

As most of the work is accomplished by (wrapped) C++ compiled code, the execution speed is comparable with pure C++ code.

Swilena Python Shell

Swilena is also usable through the Swilena Python Shell (sps). sps is an interactive loop executing Swilena/Python commands, based on the Python interpreter.

% sps
The Swilena Python Shell (sps).
Type "help", "copyright", "credits" or "license" for more information on Python
Type "example" for a short example.
Type "quit()" or ^D (Ctrl-D) to quit.
>>> example
The following example creates a 2-d image of integers with 3 rows and
3 columns, then fills its cells with the value `42' and prints it:

  ima = image2d_int.image2d_int(3, 3)
  image2d_int.fill(ima, 42)
  image2d_int.println(ima)

You can try it by copying and pasting each line on the following prompt.

>>> ima = image2d_int.image2d_int(3, 3)
>>> image2d_int.fill(ima, 42)
>>> image2d_int.println(ima)
42 42 42 
42 42 42 
42 42 42 

>>> exit()
%

Installing Swilena

You will need the following tools to compile and install Swilena/Python:

  • SWIG 1.3.35 or greater
  • Python 2.4 or 2.5 (Python 2.6 does not work yet; other versions have not been tested)

If you are installing the Olena 1.0 distribution (or greater), you can ask the build system to compile and install Swilena by passing the flags --with-swig and --enable-swilena to configure before invoking make:

1./configure --with-swig --enable-swilena
2make
3sudo make install

On more recent versions, the --with-swig flag is no longer required.

To force configure to use Python 2.5, you can use the following recipes according to you system:

On Debian GNU/Linux: Install the python2.5 package (aptitude install python2.5-dev), then set the PYHTON variable on Olena's configure command:

1./configure --with-swig --enable-swilena PYTHON=/usr/bin/python2.5

On Mac OS X, using the MacPorts: Likewise, you can install Python 2.5 by issuing the following command: sudo port install python25; then, invoke configure with PYTHON set correctly:

1./configure --with-swig --enable-swilena PYTHON=/opt/local/bin/python2.5