smilPython module
Importing
- How to import smilPython module - there are two options :
import smilPython as sp
from smilPython import *
Which option privilegiate ? Both have pros and cons :
- with the first one you need to prefix all calls to smilPython by the prefix sp (or other prefered prefix). The advantage is that this desambiguate all possible function name conflicts (e.g. read()).
- the second one is simpler, with the possible inconvenients pointed out by the another option.
- Importing smilPython error - if you get this error, or something similar, most of the time, the reason is one of these :
In [61]: import smilPython
----------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-61-ade08580f09e> in <module>
----> 1 import smilPython
ModuleNotFoundError: No module named 'smilPython'
Tips
Displaying intermediate results
If you want to display intermediate results of your processing you need to call any function which will handle the Gui interface events and refresh all images displayed by the application you're working on. Basically you have two kind of options :
- with pause waiting an order to continue : in this case, processing will stop until the user hits the
Enter
key :
7imIn = sp.Image(
"https://smil.cmm.minesparis.psl.eu/images/lena.png")
12imIn.show(
"Input image")
15input(
"Hit the enter key to continue")
18 s =
"Open SE({:})".format(i)
22 r = sp.open(imIn, imOut, se(i))
24 r = sp.write(imOut,
'res-tmp-{:03d}'.format(i))
25 input(
"Hit the enter key to continue")
27input(
"Hit the enter key to exit")
- with timed pause before continue. The call to Gui.processEvents() will do the job.
8imIn = sp.Image(
"https://smil.cmm.minesparis.psl.eu/images/lena.png")
13imIn.show(
"Input image")
16input(
"Hit the enter key to begin")
18 s =
"Open SE({:})".format(i)
22 r = sp.open(imIn, imOut, se(i))
25 sp.Gui.processEvents()
29input(
"Hit the enter key to exit")
Functions
Order of parameters - the general rule is :
- input parameters first;
- output parameters after;
- optional parameters (including structuring elements) at the end.
But there are some exceptions. In doubt, check the function prototype.
- Images as output parameters - shall allways be predefined. Their attributes will be adjusted by the called function.
imOut = sp.Image()
r = sp.erode(imIn, imOut)
There are some exceptions for attributes adjustements. For example, when you want to force the data type of the output image. One example is the labelling (label()) of an 'UINT8' input image with more than 256 connected components. In this case the data type of the output image shall be 'UINT16' or 'UINT32' imOut = sp.Image(imIn, 'UINT16')
r = sp.label(imIn, imOut)
Other Packages
smilPyGoodies
Some Goodies for smilPython
Download : smilPyGoodies
git clone https://github.com/MinesParis-MorphoMath/smilPyGoodies