A Python-Based Image Acquisition, Display,

and Analysis Program


Roger Burnham

Cambridge Research & Instrumentation, Inc.




A system for measuring stress in sheets of glass used in flat panel displays is demonstrated. The application consists of about 20,000 lines of Python code, with about 2,200 lines of SWIG (Simplified Wrapper Interface Generator) and hand generated C/C++ code. The GUI (Graphical User Interface) was written using Microsoft Developer Studio and compiled into a resource DLL (Dynamic Link Library) accessible from Python. Results of the measurements are stored and plotted in an Excel worksheet using the Python Win32 COM (Component Object Module) extension. This application demonstrates an implementation of an MFC (Microsoft Foundation Class), MDI (Multiple Document Interface) program using the Python language and extensions.


1. Background


Cambridge Research & Instrumentation (CRI) makes several kinds of electronically controllable liquid crystal (LC) optical elements. One type is a narrow bandpass filter, tunable across the visible and near IR region. The type used in this application is a polarization analyzer: The filter can be tuned to pass only light with a selected polarization state.


This application was developed to image the contrast created by samples that transmit light in a fashion depending upon the polarization state of the illumination. In general, circularly polarized light, after transmission through the sample, emerges as elliptically polarized light. By examining a series of images, each taken with calibrated polarization settings, it is possible to compute images that show the sample structures that rotated the polarization angle of the transmitted light.


Stress in glass is one such structure. Using these techniques, it is possible to measure, on a point-by-point basis, the stress magnitude (in pounds per square inch) and orientation (compression or tension) in a sheet of glass. The program illustrated here is used as a quality control tool in the manufacture of flat panel display glass where there are tight tolerances on the amount of stress acceptable to end customers.


2. Program Components


The major functional components of the application and the tools used to implement them are:


Serial control of the LC's: A commercial DLL was wrapped with SWIG and a few Python classes.


Image acquisition from a frame grabber: Again, a commercial DLL, SWIG, and a few Python classes provide the application interface to acquire images.


Image Display: The Python Imaging Library (PIL) was used to both render the images on the screen as well as create a custom image type to hold the sequence of bitmap images associated with one measurement.


Analysis of the acquired images: The core algorithm is implemented as a C++ language extension module. Much of the preprocessing is done in Python, using the numerical extension (Numpy).


User interaction: Pythonwin (Python for Windows) provided the interface to the resource DLL containing the user interface elements (menus, dialogs, etc.) and the MFC library of routines used to manipulate these GUI elements.


External program control: The Pythonwin COM extension module was used to drive the Excel spreadsheet that displays measurement results.


3. Conclusion


This application was written under very tight time and resource constraints. The fact that is was delivered on time, on budget, and, as far as the users have reported, essentially bug free is a testament to the Python community that produced these high quality components that are such a pleasure to use.

I have extracted the core framework of the application and packaged it in a tool (MDIAppTemplate) that can be used to generate a starting resource DLL and Python classes to implement a custom MDI application. This will be available at the conference (fits on one diskette).