itom
A Measurement and Data Processing
Software Suite
2013-09-10 / 2013-09-11
What this tutorial is about
• Introduction about itom
− Why did we develop itom?
− Main features
− Python and its most important modules
− itom’s plugin system
• Show-Cases
− Macroscopic fringe projection
− Software-Plugin: GUI for GPU based ray tracer MacroSim
− Commercial confocal microscope from TWIP Optical Solutions
• Hands-on exercises
− We develop an example to calculate the offset between two images,
acquired with your webcam and create a user-developed GUI
2
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
4
Motivation
Matlab Labview
Data processing Easy generation of GUIs
Extensive math libraries Excellent hardware support
Integration of hardware Limited data processing and
User defined interface analysis
No unified hardware interfaces
itom
• Fast, well-established, easy to use scripting
language (Python)
• Homogeneous hardware integration
• Automation of measurement systems
• Fast data processing and analysis
• Easy to customize
5
Requirements and Solutions
Requirements Solution
Fast, performant implementation C++
Modern, user-friendly interface, independent Qt-Framework (Windows,
of hardware platform Linux, Mac OS)
Fully integrated scripting language (fast, Python (Version 3) incl. numerous
robust, easy to learn, extensive existing libraries (numpy, scipy, scikit-
libraries, well documented and supported) image, matplotlib, …)
Easy, flexible, homogenous integration of
hardware support (motors, cameras, Plugin-System
AD converter, ...) and algorithms
Using well-known, time-proven, free software OpenCV, PointCloudLibrary,
libraries where possible Qscintilla, Qwt, …
6
itom
Windows 7
7
itom
Windows 8
Debian KDE
8
itom – main features
Scripting
- Integrated Python programming environment
- Almost full Python functionality
- Controlling itom by specific Python module
Plugins
- C++ libraries (e.g. dll)
- Hardware and algorithm integration
- Integration of complex dialogs and windows
GUI
- Intuitive
- Optimized for implementation of measurement systems
- Ability to integrate customized user interfaces
9
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
10
Python
• Open-Source scripting language (very liberal BSD-license)
• Implemented in C
• Developed and supported since 1991
• Supports object-oriented, functional and imperative programming
paradigms
• Version 3.2 or newer supported
• Fully integrated core component of itom
• Vast number of third-party modules available for free
• Scripts are precompiled and cached for faster execution
• Integrated Python-debugger
11
Python
• Variables have an Python internal type, mainly: int, float, complex
• Casting uses the functions int(), float()…
• Assignment: a=1 a,b=1,2
• Comparison operators: ==, >, <, <=, >=, !=
• Bitwise-Operators: &, |, ~, ^
• Basic arithmetic: a = a+1, a += 1, a=a**2
• Operators also work on many non-basic types (arrays, lists, dictionaries…)
Example: Factorial
function ret = factorial(x) int factorial(int x) def factorial(x):
if(x > 1) { if (x > 1):
ret = x * factorial(x-1); if (x > 1) { return x * factorial(x-1)
else return x * factorial(x-1); else:
ret = 1; } else { return 1
end return 1;
end }
}
12
Python - Packages
• Python is embedded in itom
• itom can be controlled by Python via Numpy
itom-module numeric library
• Python is extendable by packages
Scipy
scientific library
itom
scikit-image
Matplotlib
image processing
plots and graphs
tools
13
Python-Module itom
„The bridge between Python and itom“
>> from itom import * <<
• Add menus and toolbars to itom GUI and
connect them with Python methods
• Plots arrays/matrices and camera live images
• Control hardware plugins (dataIO, actuator)
• Call algorithms from software plugins
• Online help for plugins
• Build GUIs at runtime with WYSIWYG design tool
• Connect widget’s signals to python methods
• Change properties of widgets by script commands
14
Numpy
Numeric package • Array creating and
• Support of large, multi-dimensional arrays manipulation
• Binary operations
• Large library of mathematical functions and
• Linear algebra
operators • Masked arrays
• itom’s own array object is compatible to • Polynomials
Numpy arrays. • Random Sampling
• Sorting, Searching,
Counting
Example: Solve Ax=b • Fourier Transforms
from numpy import * • …
from numpy.linalg import solve
# The system of equations we want to solve for (x0,x1,x2):
# 3 * x0 + 1 * x1 + 5 * x2 = 6
# 1 * x0 + 8 * x2 = 7
# 2 * x0 + 1 * x1 + 4 * x2 = 8
a = array([[3,1,5],[1,0,8],[2,1,4]])
b = array([6,7,8])
x = solve(a,b)
print(x) # This is our solution
[-3.28571429 9.42857143 1.28571429]
15
Scipy
Scientific Algorithms • Optimization
• Extension for numpy • Linear Algebra
• Integration
• Provide more functions from the field of
• Interpolation
numeric, statistic and optimization • FFT
• Itself extendable by scikits • Signal Processing
• ODE Solvers
• Optimization
• Basic image processing
Example: • Sparse Matrices
Find root of 2 0 around 0.3
import numpy as np
from scipy.optimize import root
def func(x):
return x + 2 * np.cos(x)
sol = np.root(func, 0.3)
sol.x
>>> array([-1.02986653])
sol.fun
>>> array([ -6.66133815e-16])
16
Matplotlib
Plotting package
• Python package for math plots
• Based on numpy
• Syntax close to Matlab
• Export in various image formats:
png, pdf, eps…
• Fully integrated in itom
• Can be integrated in custom GUIs
17
scikit-image
Image processing package • Segmentation
• Transformation
• Based on Numpy arrays
• Morphology
• Algorithms written in Python and C • Measure
• Uses Matplotlib for plotting results • IO
• Image filtering
• Rank filters
• Feature detection
Example: Entropy determination
18
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
19
itom Plugin System
Plugins extend the basic functionalities of itom. Each plugin is a
C++ library (.dll, .so)
Every Plugin implements one of three basic interface classes
(DataIO, Actuator, Algorithm)
Plugins (e.g. camera, motor stages…) can be instantiated from
Python or directly through the itom GUI
DataIO Actuator Algorithm
• Cameras • Motors • Algorithms
• A/D-Converters • Multi-Axes • Data Filters
• Serial Bus Machines • Complex GUIs
20
Interface “dataIO + Grabber”
Primary functionality
• getParam(..) read a parameter
• setParam(..) set a parameter
• startDevice() start camera
• stopDevice() stop camera
• acquire() take a picture
• getVal(..) / copyVal(..) load
image from camera into
itom/Python
• …
Live images from the camera can be displayed in separate windows or
integrated into custom GUIs
21
Interface “actuator”
Primary Functionality
• getParam(..) read Parameter
• setParam(..) set Parameter
• getStatus(..) get status per axis
• getPos(..) read current position
• setPosAbs/Rel() move to position
• …
Signals about position and status of the actuator can be linked to and
processed by the GUI.
22
Interface “algo”
‚Algo‘ plugins define
• Numerical algorithms
• GUI elements
Call:
• From a Python script
• By other plugins
Each method is defined by :
• Mandatory parameters (Type,
description…)
• Optional parameters
• Return values
23
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
24
GUI
25
GUI – Command Line
• Input/Output window for Python (Information, Warnings, Error)
• Direct execution of Python commands
• Functionality very similar to Matlab
• Auto completion of commands
• Syntax help and highlighting
26
GUI - Workspace
• Global Variables: contains all globally defined variables
• Local Variables: all local variables within a function (Debug only)
• Direct import and export to / from the Python workspace
27
GUI – File System
• Access and administration of all scripts
and files that can be opened in itom
• The default main directory is the current
working directory (similar to Matlab)
• Double click on a .py Python script will
open it in the scripting window
• Double click on supported file types will
load them into workspace
28
GUI – Plugins
• List of all available Plugins
• Sorted by category
• Allows direct instantiation of hardware
plugins
29
Scripting window
• Editor for Python scripts
• Syntax help and highlighting
• Auto completion
• Standard editor functionality
• Tabbing of multiple scripts
• Dockable into the main GUI
• Executes Scripts
• Full debugging functionality
30
Syntax Help and Auto Completion
• Auto completion Set various syntax-files (for
(selection item with tab-key) important Python modules)
in itom’s property editor in
order to enable these
features.
• Syntax help
31
Plots
• 1D, 2D, 2.5D plots
• Custom windows can be implemented
• Displayed in
− A separate window
− Docked into the main GUI
− Integrated into a custom GUI
dependent 1D-line plot
32
Custom GUIs (Qt Designer)
• Design of custom GUIs in the external Qt Designer
WYSIWYG tool (drag&drop).
• Events created by the GUI (button click) can be
linked to Python functions
Preview
Elements custom
GUI:
• Hierarchy
• Layouts
Library of Properties of each
elements element:
Can be adapted by
Python scripts in
itom Designer- itom
Plugins 33
Custom GUIs (Qt Designer)
Dialog design with Qt Designer:
Dialog: gui
Script logic with python:
gui.btnOk[“text”] = “OK”
1. Access properties gui.comboOs.call(“addItems”, [“Windows”,”Linux”])
2. Connect signals with def clickMe():
print(“operating system”, gui.comboOs[“currentText”])
Python methods
gui.btnOk.connect(“clicked()”, clickMe)
34
Multithreading
Main Thread Plugin Thread
All GUI Elements Asynchronous
• Main Window Communication
Each plugin runs
• Scripting using Qt-
in its own,
Window Signal/Slots
separate thread.
• Plots
The corresponding
GUI elements are
Script Organizer
pushed to the
Python Thread main thread.
UI Organizer
Python Interpreter
Plugin Organizer
Python Debugger
…
35
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
36
License
• itom (main application) is “Open Source” (LGPL)
• itom-SDK (resources common to the main application and plugins)
are distributed under the LGPL-licence + itom-exception. The itom
exception allow the inclusion and linking of additional components
independent of those components licensing against all data included
in the SDK.
• Plugins can be subject to any (including proprietary) licenses. The
ITO offers a number of generic plugins under the LGPL.
• Designer-Plugins (plots…), similarly, can be subject
to any licenses.
37
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
38
Data Object
Goal:
• Different basic types of data (including complex)
• Processing of large, multi-dimensional data sets (series of images)
• Compatible with Matlab, Numpy, OpenCV
Implementation:
• DataObject very similar to OpenCV data structures
• Basic data types supported: int8, uint8, int16, uint16, int32, uint32, float,
double, complex(float), complex(double)
• DataObject supports tags (axes units, descriptions, title…)
39
Data Storage
Series of 2D-images
3D data stack
Plane 0
Plane 1
Plane 2
40
Data Storage
Assume: Series of 2D-images (3 x 2 x 5)
(0,0,0)
Plane 0
Plane 1
Plane 2
(2,1,0) (2,1,4)
C / Matlab: continuous chunk of memory
(0,0,0) (0,1,0) (1,0,0) (2,1,4)
Plane 0 Plane 1 Plane 2
+ Uniform, quick and easy access to multi-dimensional arrays
– Memory allocation error for „big“ arrays
41
Data Storage
DataObject:
0 (0,0,0) (0,1,0) Plane 0
1 (1,0,0) Plane 1
2 (2,1,4) Plane 2
+ Less allocation errors due to distributed chunks of memory
– Slightly more complex access to memory
DataObject (continuous): Compatibility to C-style arrays
0 1 2
(0,0,0) (0,1,0) (1,0,0) (2,1,4)
Plane 0 Plane 1 Plane 2
42
Agenda
• Motivation. Why itom?
• Features
• Script Language Python
• Modular Plugin System
• The Graphical User Interface
• Licensing
• DataObject – itom’s Built-in Array Class
• Documentation and Help
43
User Documentation
• User documentation displayed with Qt Assistant
• Can be exported to pdf, html…
Help pages
• Table of content
• Search
• Bookmarks
itom.bitbucket.org/latest/docs
44
Additional User Help within Python
1. Syntax help and auto completion in
the Python editor
2. Customizable, context sensitive
syntax highlighting
3. Python-internal help system using the
command help(…)
4. Additional information and help about
available plugins or algorithms using
the commands
pluginHelp(…),
filterHelp(…),
widgetHelp(…)
45
itom
Questions?
46
itom
Show Cases
Show-Case I: Fringe Projection
Situation
A flexible fringe projection setup
(structured light) for student
projects and public presentation is
been developed
Objective
Provide a GUI for such a system
to demonstrate the function
Allow students to run batch
processes for system
characterization
Provide flexibility to change between several
evaluation or calibration methods and hardware
components.
48
Show-Case I: Triangulation
Laser
camera
chip
H ∆x
camera lens
∆z
object
49
Show-Case I: Structured Illumination
Cosine-fringes (mod 2PI)
LCOS-Display or
DMD-Projector
absolute coding
Grey-Code
50
Show-Case I: Basic Set-up
Camera + lens
Projector
51
Show-Case II: MacroSim
Situation
An open source GPU based ray-tracing tool has been
developed at ITO
The native tool is command-line based
Objective
Provide a GUI for MacroSim in order to simplify the
creation of new scenes and execute simulations
For the future it should be possible to run both the real
setup and its corresponding simulation with the same tool.
52
Show-Case II: MacroSim
Solution
Create an itom software plugin that provides its own GUI
and communicates with the tool MacroSim
itom MacroSim
MacroSim Tracer
Plugin
MacroSim can use functionalities contained in itom
Tracer can also be started by Python
Batch execution possible using appropriate Python script
Results of tracer are available in itom
53
Raytracing: A versatile tool
Raytracing is perfectly linear
→ Raytracing is perfectly parallelizable
Modell adaptiert von US Patent Publication US 6522484 B1, K-H
Schuster, Carl-Zeiss-Stiftung, (1999) 54
Parallelization of Raytracing
CPU-Parallelization
- very flexible
- straightforward implementation
- More than 4 cores quickly become expensive
GPU-Parallelization
- Restriction to Thread Coherence
- Specific Implementation
- Standard GPUs come with 200-500 cores
Images taken from CUDA programming guide 3.2 56
Parallelization of Raytracing
GPU-Parallelization
- Restriction to Thread Coherence
- Specific Implementation
- Standard GPUs come with 200-500 cores
GPU accelerated Tool: MacroSim
- Based on nVidia® OptiX™ acceleration engine
- Plugin to ITOs itom software
- imports glass catalog from Zemax®
- Published under GPL at https://bitbucket.org/itom/macrosim
- „An open source GPU-accelerated ray tracer for optical simulation“,
submitted for publication to Optical Engineering.
Images taken from CUDA programming guide 3.2 57
Parallelization of Raytracing
MacroSim Plugins contains one GUI and
some callable functions
58
Interaction with itom
GUI based
• Start MacroSim GUI by Python command (createNewPluginWidget)
• Start simulation manually
• GUI emits a signal with the final detector matrix (dataObject)
• Connect a Python function to this signal (called when simulation done)
Script based
• Optional: Start MacroSim GUI and create scene (XML-file)
• Call function runSimulation of MacroSim plugin and pass XML-file
(simulation is executed)
• The function finally returns the detector matrix as dataObject
59
Show-Case III: Confocal Microscopy
60
Show-Case III: Confocal Microscopy
Situation
A confocal microscope is being developed by Twip Os
(spin-off of ITO)
Objective
itom should be used to…
− control the measurement process
− provide a user-friendly control panel
− visualize the results
− provide functionality for data evaluation (roughness,
alignment, geometrical fitting…)
61
Show-Case III: Confocal Microscopy
Object
FWHM ~ 1/NA
Point Detector
62
Show-Case III: Confocal Microscopy
Object
Point Detector
63
Show-Case III: Confocal Microscopy
GUI
64