ShapeLogic is an open source toolkit for declarative programming, image processing and computer vision. Started August 2007.

Code hosted on . From there you can download both source files and binary distributions.

Join the ShapeLogic mailing list for announcements, questions, bug reports, suggestions and feature requests.

Main ideas and motivation

ShapeLogic is a library for

While ShapeLogic's declarative programming system was initially developed for image processing and computer vision, it is widely applicable. It is currently difficult to combine declarative programming and image processing. ShapeLogic is intended as basic plumbing software that turns a logic engine into a simple plugin component to ease entry into vision and image analysis. ShapeLogic also fills gaps missing from current Java image processing libraries, and uses a commercially friendly license.

ShapeLogic has an automatic color particle counter and a letter matching example .


  • Declarative lazy stream driven logic engine with lazy computations
  • Specialized for the domain of image processing and computer vision
  • The user can store rules in either a flat file or database, decreasing user reliance on Java programming
  • User rules are written with Java or the Java 6 Scripting interface JSR 223. Groovy , JRuby , JavaScript have been tested
  • Implementation of 2D geometry primitives, vectorization and segmentation
  • It is free (as in free speech and free beer)
  • Commercially friendly MIT open source software license, also called the X11 License
  • Annotations of point as different type of junctions, end points, hard or soft points
  • Annotations of lines as straight, curved, concave or inflection points
  • Programmed in Java
  • Can be used as a plugin for ImageJ, the leading Java open source project used in medical image processing


For running as a library for functional and declarative programming there are no requirements.

For running as a ImageJ plugin ShapeLogic uses the following libraries:

  • ImageJ ShapeLogic can either run as a plugin in popular ImageJ framework or stand alone in pure Java2D
  • Commons math : Math library for geometry
  • Antlr : For parsing build in filter language

You can run all current image processing algorithms outside ImageJ , using just a BufferedImage. If you want to embed ShapeLogic in your application.

Optional requirements

These are used in unit tests, builds or old versions of image processing functionalities:

Development Status: Beta

  • ShapeLogic is in Beta, as of version 1.0.
  • Particle counter working directly on color images without manual user intervention.
  • Working example where ShapeLogic is used for matching capital letters.
  • Image processing algorithms now work both in ImageJ and on Java's BufferedImage .
  • The API is still under development.
  • Contains a framework for declarative and functional programming.
  • ShapeLogic currently consists of 29,000 lines of Java code including 440 unit tests.


2008/05/07 ShapeLogic v 1.1 released

  • Particle counter working directly on color and gray scale images without manual user intervention
  • Particle counter finds average color, standard deviation, area and location for each particle
  • Framework to build more advanced particle counters and particle analyzers
  • Color clustering using K-mean algorithm
  • Background color finder
  • First use of ShapeLogic in medical image processing
  • Extends all the image processing algorithms in ShapeLogic to work in both ImageJ and in plain Java

The particle counter in ShapeLogic v 1.1 has gone through limited testing, and seems to work well though tweaking the parameters is still a bit clumsy. Users looking for a mature particle counter should probably wait for ShapeLogic v 1.2.

Documentation will soon be updated to reflect ShapeLogic 1.1.

Future plans for ShapeLogic

For more up to date information on ongoing development work look at these

ShapeLogic v 1.2 with particle analyzer soon to be released

  • More testing and improvement of particle counter
    • Make it easier to set parameters in a macro or a configuration file
    • Improve to handle blobs.gif image shown here, this was not recognized as a particle image under ShapeLogic 1.1
    • Enable ROI, 1.1 only works on whole images
  • Particle analyzer
    • Suitable for processing cells and organelles
    • Expand the particle counter to a full featured particle analyzer
    • Print report about each particle's color, area, standard deviation to a file
    • Vectorize particles by tracing the edge into polygon
    • Filter particles based on geometric properties of the edge

The test images are taken from the sample images from ImageJ




Examples applications

  1. Automatic color and gray scale particle counter , first medical image processing example.
  2. Letter matching example . Very rudimentary OCR.
  3. Mathematical problems from Project Euler . This is a list of 193 mathematical problems that can be solved by computers. They vary in complexity from simple to hard. The goal is to test ShapeLogic's new declarative and functional constructs on real problems and make sure they are terse and intuitive.