User Tools

Site Tools



Main ShapeLogic menu


The ShapeLogic plugin add the ability to create rule based programming under ImageJ, for categorizing particles and lines. ShapeLogic has a framework for functional and declarative programming, using lazy streams.


Sami Badawi


Currently there are 2 applications and a few utilities.

Color Particle Analyzer

This works directly on a color image and find gray and color average color of each particle.

Can run in different modes:

  • Automatic mode finds background color using K-mean method
  • Set background color
  • Set foreground color


  • It will find and categorize particles on a relatively uniform background then
  • Trace the edge for the particles
  • Vectorize them to polygons
  • Annotate the polygon with geometric properties
  • Categorize based on user defined rules

Currently there is only a example categorization, based on the aspect ration and color intensity. The syntax for the rules for this categorization is the same as for the letter match. See below.


Part of ImageJ sample image embryos.jpg

 Part of ImageJ test image embryos.jpg

Output if mask option was checked

 Output if mask option was checked

Set input parameters manual and automatic mode

 Input dialog  Input dialog

Particle count dialog

 Particle count

Particle property result table

 Particle properties

Since ShapeLogic 1.4 there is also a mean R, B and G channel for color images

OCR example

ShapeLogic also contains a rudimentary OCR example that analyzes skeletonized lines and matches the to rules for capital letters.

This is a proof of concept not an attempt to make a The point was not to set up a


Input example:

Call ShapeLogic → CapitalLettersMatch

You will see the skeletonized lines, and the vectorized polygon in gray lines

Result is presented as a dialog box with a letter match for each polygon

Rule syntax

Rule for the letter A in the letter match example:

rule("A", POINT_COUNT, "==", 5., letterFilter);
rule("A", HOLE_COUNT, "==", 1., letterFilter);
rule("A", T_JUNCTION_LEFT_POINT_COUNT,"==", 1., letterFilter);
rule("A", T_JUNCTION_RIGHT_POINT_COUNT,"==", 1., letterFilter);
rule("A", END_POINT_BOTTOM_POINT_COUNT, "==", 2., letterFilter);
rule("A", HORIZONTAL_LINE_COUNT, "==", 1., letterFilter);
rule("A", VERTICAL_LINE_COUNT, "==", 0., letterFilter);
rule("A", END_POINT_COUNT, "==", 2., letterFilter);
rule("A", SOFT_POINT_COUNT, "==", 0., letterFilter);

There is a digit matcher that show how to make your own categorizer. Currently you have to do it in Java, but it is trivial to load the rules from database or flat file instead.

Machine learning

The user will be able to choose between handwritten rules and rules generated by machine learning for particle categorization. Starting in ShapeLogic 1.6 this will be ported to OCR. First machine learning technique is a multi-layer feed forward neural network that is trained externally but run internally.


Project web site


Both source files and binary distributions can be downloaded here: .


MIT license

plugin/analysis/shapelogic/start.txt · Last modified: 2019/04/12 13:13 by

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki