The is a python script that allows you to extract distances and locations from a digital image. It can be used for example to analyze the interference pattern of the Fabry Perot interferometer to measure the line splitting observed in the normal Zeeman effect experiment. It can also be used to extract numerical values from a scanned image of a graph and in future experiments that are using a digital camera.

Quantitatively analyzing a digital image involves:

  1. Calibrating the image to determine a conversion factor between pixel positions and the corresponding real world positions.
  2. Extracting pixel locations and converting them into world positions and saving them in a data file.
  3. Measuring the distance between 2 points on the image.

Using the Program

You can download and unzip it. The script can be started by either double clicking on IA.bat (Windows) or IA.command (Mac OS X) or starting it on Linux or Mac Os X in a canopy terminal window as

python ./


pythonw ./

or from within canopy:

%run ImageAnalyzer1

When on Mac OS X you double click IA.command and the program does not start with a message like: The file “IA.command” could not be executed because you do not have appropriate access privileges. you need to run:


in the directory where you extracted Then it should work.

The program opens a blank graph (Fig. 1):


Figure 1: Image analyzer opening screen.


As a first step you should determine the calibration factors. For this, purpose you took an image of a ruler. Use the menu to open a file (Fig. 2):


Figure 2: Open a file.

Once the calibration image has been loaded you can start with the calibration (Fig. 3):


Figure 3: Start calibration.

Note that as soon as you clicked Calibrate the status in the lower right corner changes to calibrate. By clicking and holding down the left mouse button you can enter the first and the second calibration points. As soon as you release the button you are presented with a dialog asking you for the type of calibration (Fig.4).


Figure 4:

You can either use the x-displacement (X-axis) or the y-displacement (Y-axis) to determine the common (for both axes) calibration factor, or you can select to enter independent calibration factors for both axes (X/Y independent). Once you have made your selection a dialog windows opens where you can enter the corresponding displacement in world (e.g. mm) units (Fig.5).


Figure 5:

Once the calibration is completed you see the 2 displacements labeled with the corresponding distances.

This is a good moment to save the calibration into a data file. From the menu select File \rightarrow Save As and enter the file name you want to use.

Performing Measurements in an Image

Once you have calibrated your image you can extract measurements between different points and have them drawn and labeled on the image. First open an image file (Fig. 6):


Figure 6:

This will open the new image but keep your last calibration constants. From the Analyze menue select Measure (Fig. 7):


Figure 7:

Then move the cursor to the fist point of your distance measurement and click and hold the left mouse button. Drag the cursor to the second location and release it. The measured distance will be drawn and labeled in pixel as well as user units (see Fig. 8)


Figure 8:

Picking Positions

You can also extract position information from the images you took. When you have to pick locations in the image it is often useful to zoom into that part. You can do this by clicking on the icon at the edge of the image (indicated by a yellow arrow in Fig. 9):


Figure 9:

Click and drag the zoom-rectangle over the area you would like to enlarge (Fig. 9a):


Figure 9a:

You will then see the selected portion of the image (Fig. 10). It is important that you turn off zooming by again clicking on the magnifying icon (yellow arrow in Fig. 10.


Figure 10:

To start picking points select Analyze \rightarrow Pick Points (Fig. 11)


Figure 11:

To pick a point just left-click on the location. The program will store the position and draw a marker. While you are entering positions the status will show: enter positions (Fig. 12).


Figure 12:

Important terminate entering positions with a right-click. The status will go back to idle. Now you can save your positions again selecting :File \rightarrow Save\ As and enter the file name or pick an existing file to overwrite. Your positions and you calibration factors are now saved in this file. You will also get another image file with the same name containing you marked positions. The data file can be read with the standard tools. The file contents typically looks as follows:

# data points from file : /Users/boeglinw/IA/Zeeman/zm8.png
# xpc and ypc are positions in calibrated user units (e.g mm)
# Calibration information
#\ convx_av =  2.5224e-02
#\ convy_av =  2.5224e-02
#! n[i,0]/ xp[f,1]/ yp[f,2]/ xpc[f,3]/ ypc[f,4]/
0  1.8375e+02  2.3969e+02  4.6348e+00  6.0460e+00
1  4.5658e+02  2.4180e+02  1.1517e+01  6.0992e+00

The meaning of each variable is as follows:

Name Meaning
convx_av x-axis calibration factor (parameter)
convy_av y-axis calibration factor (parameter)
xp pixel x-coordinate
yp pixel y-coordinate
xpc x-coordinate in world units
ypc y-coordinate in world units

Loading a Calibration from an Existing Data File

You can load the calibration from a saved data file and use it for further image analysis, this occurs if you calibrated your image and analyzed a few images but had to close the program and now you would like to continue. In this case you load the calibration parameters from your saved data by doing Calibration \rightarrow Load\
Calibration and select your data file. Now you should be ready to open and image file and pick locations. You can always check your current calibration constants using Calibration \rightarrow Show which will show you the current parameters for the x-axis and y-axis. You can also enter them by hand.