Getting Started

You can use ShapeLogic in different ways:

  • User mode for ImageJ image processing plugin
  • Development mode for ImageJ plugin
  • As a lazy stream library

Testing ShapeLogic as a user is very simple and only takes a few minutes after ImageJ is installed.

Lazy stream library

ShapeLogic contains functional and declarative constructs that can be used independently of the image processing code.

To use this just download the shapelogic_-1.2.jar and add it to your class path. If running from command line: -cp .;shapelogic_-1.2.jar

For examples of how to use this to solve mathematical problems see Project Euler solution .

Image processing user mode with ImageJ

Steps to get ShapeLogic working from within ImageJ, from binary distribution

  • Install ImageJ
  • Download shapelogicplugin1.2.zip
  • Unzip it
  • This will create a directory named shapelogicplugin
  • Take everything from this directory and copy it into ./ImageJ/plugins/

Testing ShapeLogic particle counter or particle analyzer from within ImageJ

  • Open a particle image
  • Under the shapelogic plugin menu select Particle Counter or Color Particle Analyzer
  • Enter input parameters in dialog
  • A result table with geometric information for each particle will be displayed

For more information see Particle Counter and Analyzer page .

Testing ShapeLogic letter matching from within ImageJ

  • Open ImageJ
  • Create a new image, 100 x 100 pixels works well
  • Draw a letter in black on white background
Mdrawing
  • Go to the shapelogic menu and select CapitalLettersMatch, which does the following
    • Convert the image to a binary image
    • Call ImageJ's build in Skeletonize
    • Vectorize into bitmap into polygon
    • Clean up the vectorized polygon
    • Then annotate the polygon
    • Then match the polygon against all the rules for all the capital letters
    • With a little luck you will see a dialog box saying what letter was matched
    • If more than one letter matches, the match will fail
    • If the match fails then all the properties of the polygon will be written to the console for debugging

Result of match

Dialog with results of match

M match

Vectorized M with skeletonized letter in black and polygon in gray

M vectorized

For more information see Letter Match page .

Steps to get ShapeLogic working from within ImageJ manually

If you need a different version of shapelogic_-1.2.jar, e.g. one compiled for JDK 1.5.

  • Create a ShapeLogic dir under ImageJ: ./ImageJ/plugins/ShapeLogic
  • Take the jar file for ShapeLogic: shapelogic_-1.2.jar, and move it to that directory
  • Add the jar files that ShapeLogic is dependent on to the ImageJ/plugin dir:
    • antlr-runtime-3.0.jar
    • commons-collections-3.2.jar
    • commons-jexl-1.1.jar
    • commons-logging-1.0.4.jar
    • commons-math-1.1.jar
    • guice-1.0.jar

These jar file can be found on any Maven 2 repository:

E.g. commons-math-1.1.jar can be found here: http://repo1.maven.org/maven2/commons-math/commons-math/1.1/

Or they can be taken out of the shapelogicplugin1.2.zip

When you open ImageJ there will be a ShapeLogic menu containing commands.

You can get the binary distribution from the download page or compile it yourself.

User defined rules in ShapeLogic

Starting in ShapeLogic 1.0 it is simpler to make user define rules for matching for use in letter matcher or the particle analyzer .

Number match example

DigitStreamVectorizer is an example showing what is needed to define a match of the numbers.

To run this from ImageJ in the shapelogic menu select

  • Digit Match Stream Vectorizer, to only do the vectorize and number match
  • DigitMatch, to also turn into binary and Skeletonize
public class DigitStreamVectorizer_ extends StreamVectorizer_ {

        @Override
        public void matchSetup(ImageProcessor ip) {
                loadDigitStream();
                
        }
        
        public static void loadDigitStream() {
                LoadPolygonStreams.loadStreamsRequiredForLetterMatch();
                makeDigitStream();
                String[] digits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; 
        LoadLetterStreams.makeLetterXOrStream(digits);
        }

        public static void makeDigitStream() {

                rule("0", HOLE_COUNT, "==", 1.);
                rule("0", T_JUNCTION_POINT_COUNT, "==", 0.);
                rule("0", END_POINT_COUNT, "==", 0.);
                rule("0", MULTI_LINE_COUNT, "==", 1.);
                rule("0", CURVE_ARCH_COUNT, ">", 0.);
                rule("0", HARD_CORNER_COUNT, "==", 0.);
                rule("0", SOFT_POINT_COUNT, ">", 0.);

                rule("1", HOLE_COUNT, "==", 0.);
                rule("1", T_JUNCTION_LEFT_POINT_COUNT, "==", 0.);
                rule("1", T_JUNCTION_RIGHT_POINT_COUNT, "==", 0.);
                rule("1", END_POINT_BOTTOM_POINT_COUNT, "==", 1.);
                rule("1", HORIZONTAL_LINE_COUNT, "==", 0.);
                rule("1", VERTICAL_LINE_COUNT, "==", 1.);
                rule("1", END_POINT_COUNT, "==", 2.);
                rule("1", MULTI_LINE_COUNT, "==", 0.);
                rule("1", SOFT_POINT_COUNT, "==", 0.);
                rule("1", ASPECT_RATIO, "<", 0.4);
                
        }
}

This file is not defined inside the shapelogic package system.

Users do not need to download the source file for ShapeLogic to use it, they only need shapelogic and other dependent jar files.

Future plans for user defined rules in ShapeLogic

Defining rules in a stand alone Java file is very simple, but you still have to compile the Java file. ShapeLogic's goal is to make rule definition as effortless as possible.

With an extended rules set it should be easier to define rules in a database, ShapeLogic will add a menu item in ImageJ for doing this.

Development mode

ShapeLogic is built using Maven 2 .

This makes several build tasks very easy, and is recommended, but the code should run fine without Maven.

Currently the project is set up to work directly with Eclipse 3.3, NetBeans 6.0 - 6.1, Java 1.6, but you can use: IntelliJ, JBuilder, emacs or vi.

  • Steps to compile and run unit tests

Check ShapeLogic out into a local directory.

Do a cd into that directory.

Run:

  • mvn test runs the unit tests locally
  • mvn package runs the unit tests locally, and if they passes it will create the jar file
  • Changing JDK version when building with Maven

You will have to change the JDK target in pom.xml:

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>