Regarding examples
All the examples in this section are meant to give you an overview of the
possibilities given by the Mamba Library. They can be used as a starting
point for coding your own applications.
To understand them, we strongly recommand you to read the tutorial which
is available in the documentation page.
For all the examples below, we use the following image :

This is a small size version of this
image.
To be able to see the examples, you must have javascript enabled in your
browser.
Erosion : a simple example

Erosion of an image along an hexagonal grid (script).
1 # importing the mamba module and the erosion function
2 from mamba import *
3 from mambaComposed.erosion import erodeInAllDirImage as erosion
4
5 imIn = imageMb('snake.png')
6 imOut = imageMb()
7 erosion(imOut, imIn)
8 imOut.showDisplay()

Minima by dual reconstruction

This example find the minima of an image using reconstruction.
The resulting image is a binary image (script).
1 # importing the mamba module and the reconstruction functions
2 from mamba import *
3 from mambaComposed.build import *
4
5 def minima(imOut, imIn):
6 im_rebuild = imageMb()
7 imout_prov = imageMb()
8 copyImage(im_rebuild, imIn)
9 addconstImage(im_rebuild, im_rebuild, 1)
10 dualbuildImage(im_rebuild, imIn)
11 subImages(imout_prov, im_rebuild, imIn)
12 thresholdImage(imOut, imout_prov, 1, 255)
13
14 imIn = imageMb('snake.png')
15 imOut = imageMb(depth=1)
16 minima(imOut, imIn)
17 imOut.showDisplay()

Thick gradient

This example computes the thick gradient of the image (thickness set to 3).
The example also shows the use of a color palette for display (script).
1 # importing the mamba module and the gradient functions
2 from mamba import *
3 from mambaComposed.gradient import *
4
5 imIn = imageMb('snake.png')
6 imOut = imageMb(depth=1)
7 gradientImage(imOut, imIn, 3)
8 imOut.setPalette(rainbow)
9 imOut.showDisplay()

Watershed line

This example computes the watershed of the image using the minima of its gradient (script).
1 # importing the mamba module, the gradient and the reconstruction functions
2 from mamba import *
3 from mambaComposed.gradient import *
4 from mambaComposed.build import *
5
6 def minima(imOut, imIn):
7 im_rebuild = imageMb()
8 imout_prov = imageMb()
9 copyImage(im_rebuild, imIn)
10 addconstImage(im_rebuild, im_rebuild, 1)
11 dualbuildImage(im_rebuild, imIn)
12 subImages(imout_prov, im_rebuild, imIn)
13 thresholdImage(imOut, imout_prov, 1, 255)
14
15 imIn = imageMb('snake.png')
16 imOut = imageMb()
17 imGrad = imageMb()
18 imMinima = imageMb(1)
19 imLabel = imageMb(32)
20
21 # We compute the gradient and its minima
22 gradientImage(imGrad, imIn)
23 minima(imMinima, imGrad)
24 # Each minimum is labelled
25 labelImage(imLabel, imMinima)
26 # Then each label is used as a well to
27 # flood the gradient image
28 watershedSegmentImage(imLabel, imGrad)
29 # The watershed is extracted from the last
30 # byte of the label image
31 copyBytePlaneImage(imOut, imLabel, 3)
