Recently viewed:

Formulas 1 - Basic Shape Analysis


Formulas make it possible to extend ProSEM’s analysis capability to report what you need.  Formulas use the JavaScript programming language, but in many cases, it is not necessary to learn much JavaScript syntax.  For more complex needs, there is plentiful online documentation and lessons for JavaScript programming.

To demonstrate formula basics, here some characteristics of measured shapes are computed using user-defined formulas, such as Aspect Ratio of rectangles, Circular shape computations such as circularity or ellipticity, or grating metrics such as duty cycle or fill fraction.


Note: ProSEM 2.3.0 or higher is required for these examples. 




Measurement Example 1: Aspect Ratio 

In this first example, a formula is created to compute the Aspect Ratio of measured rectangles. 

1)      A measurement of a rectangle is setup, stored, and then that stored measurement is selected in the tree in the Images panel.

Rectangle Measurement Setup

2)      In the Variables panel, the “Create New Variable…” button is clicked. In the dialog:

Create New Variable dialog


3)      Optional:  the new formula can be tested using the “Evaluate” button.  If the variable is successfully setup, the value displayed will be the Aspect Ratio of the selected measurement.

4)      The OK button is clicked to complete the creation of the new formula variable.

This formula will be evaluated for all measurements in the project, including measurements already stored and all measurements stored after the variable is created.  The values of any defined variables for the currently selected measurement are shown in the table in the Variables panel.

Aspect Ratio measurement displayed in the variables panel

In addition, each variable defined will appear as a new column in each data table, so in this case, the value of Aspect Ratio will be calculated for all rectangles measured in the project.

Aspect Ratio variable in data tables





Measurement Example 2: Eccentricity, More Shape Computations, using the Object Browser and Snippet Gallery 

In this example, the Eccentricity, also sometimes called Ellipticity, of ellipses and circles is computed, and the Object Browser and Snippet Gallery are introduced.

To compute the Eccentricity of measured Ellipses and Circles, the formula to be used is: 

 eccentricity formula

Where a is the semimajor axis, or half the length of the major axis, and b is semiminor axis. 

But how does one know the property names within ProSEM for these measured values?  The Object Browser is displayed on the right side of the Edit Variables dialog when a Formula is being edited, and contains all of the properties of the selected measurement, as well as the group and the image containing the selected measurement. 

For this example, a multi-line formula will be used, to increase the readability of the formula.  So first a and b will be defined as variables, and then the full formula will be computed using those variables. 

For example, to compute the Eccentricity of a measured ellipse:

1)      An ellipse measurement is setup, stored, and then the stored measurement selected n the Images tree.

Ellipse Measurement Setup

2)      In the Variables panel, a new variable is created.  In the Create New Variable dialog:

To compute the eccentricity, the lengths of the semimajor and semiminor axes are needed, each half of their respective diameters.  Within the formula, these will be stored as local variables named a and b.  The length of the major and minor axes could be typed into the formula, or in this case, the property name is drag-and-dropped from the Context branch of the Object Browser.  Each line is terminated by a semicolon character “;” keeping with JavaScript syntax requirement. 


Eccentricity Formula, step 1

Formula action 2


The complete formula contents for the Eccentricity in this example are:

a = MajorDiameter / 2;
b = MinorDiameter / 2;
sqrt(1- (pow(b,2) / pow(a,2)))

This could also be written on a single line as: 

sqrt(1- (pow((MinorDiameter/2),2) / pow((MajorDiameter/2),2)))




The formulas in this example demonstrate some basic elements of using Formulas in ProSEM.  See other examples on this site for more advanced examples.