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.
1 import data 2 from swilena import * 3 4 image = image2d_int_u8 5 6 # Input. 7 ima = image.load("lena.pgm") 8 9 # Gradient. 10 gradient = image.gradient(ima, win_c4p()) 11 12 # Area closing of the gradient. 13 closed_gradient = image.closing_area(ima, c4(), 50) 14 15 # Watershed transform. 16 nbasins = int_u8() 17 ws = image.meyer_wst (closed_gradient, c4(), nbasins) 18 19 # Output. 20 print nbasins 21 image.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() %
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 2 make 3 sudo 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
1 ./configure --with-swig --enable-swilena PYTHON=/opt/local/bin/python2.5