2. Introduction to Python for Image Processing And Computer Vision¶
The combination of Python (the language), Numpy (the numerical array lib), SciPy (scientific libs) and Matplotlib (the graphical plot lib) will serve as our computational basis to learn image processing and computer vision. Where possible and needed we will use other libraries as well. We will use the name ‘Python’ to refer to this collection of tools.
The best way to explore Python is by using it. We assume that you have
ipython
installed on your computer. All interaction shown is from
actual ipython
sessions. Start ipython
with the command
ipython
.
You can start right away typing commands into the command line window:
The interpreter executes this statement and shows nothing (meaning
that there were no errors). We may look at the value of variable x
by just typing its name:
In [1]: x
Out[1]: 2
In Python there is no need to declare variables before using them.
If you start losing the overview over which variables you have already
used and which data they contain, the command whos
can help you
out.
In [2]: whos
Variable Type Data/Info
------------------------------
np module <module 'numpy' from '/ho<...>kages/numpy/__init__.py'>
plt module <module 'matplotlib.pyplo<...>es/matplotlib/pyplot.py'>
x int 2
In case you are not familiar with Python we suggest that you work your way through one of the tutorials that are available on the web (see some suggestions here).
In Python the list and dictionary are probably the most important datastructures. A list is a heterogeneous sequence of values (numbers, strings, lists, dictionaries, functions, really anything).
In [3]: a = [ 1, 2, 3, 4, 5 ]
In [4]: a[0]
Out[4]: 1
In [5]: a[3]