Particle Counter and Analyzer

ShapeLogic v 1.1 contains the first version of an automatic color and gray scale particle counter working without manual user intervention.

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

Test on sample images from ImageJ

The particle counter was tested on the particle images from ImageJ:

embryos.jpg. The un-tweaked particle counter in ShapeLogic 1.1 found

particle count = 9

embryos.jpg contains 6 particles and a few shadows.

After changing the parameter setting it found

particle count = 5

which is the correct value since ShapeLogic 1.1 cannot split overlapping particles.

Cell_Colony.jpg. It is hard for a human to count the particles in this image but ShapeLogic v 1.1 gave a reasonable result.

blobs.gif. ShapeLogic v 1.1 did not recognize this as a particle image.

Parameters that gave correct match for embryos.jpg

_iterations = 4; // K-mean iterations for color hypothesis
_maxDistance = 90; // Distance between color in same color bucket
_minPixelsInArea = 70; // Minimum number of pixels in particle

Information for each particle in ShapeLogic v 1.1

  • Average color
  • Standard deviation
  • Center of gravity
  • Area
  • Bounding box
  • Start point

This information is available but there is no print report function in 1.1.

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

Usage

There is just one step. Under shapelogic menu click "Particle Counter".

A dialog will appear with the following information:

  • How many regions were found
  • Background color
  • If the image was a particle image
  • The number of particles
  • The number of colors in the color hypothesis

Framework to build more advanced particle counters and particle analyzers

The particle counter algorithm in ShapeLogic 1.1 is relatively simple. It is setup to be expanded to handle more advanced algorithms. Here is the flow.

  • Find one or more color hypothesis
    • Color clustering using K-mean algorithm
    • Background color finder
  • Check that image is a particle image, if it is not stop
  • Run over the image again find the individual particles based on the color hypothesis
  • Collect color and area information for each particle
  • Filter particles based on size

Particle counter functionality can be tweaked by setting parameters

Here are the parameters you can set with their default values:

int _iterations = 2; // K-mean iterations for color hypothesis
double _maxDistance = 50.; // Distance between color in same color bucket
int _minPixelsInArea = 5; // Minimum number of pixels in particle

How to tweak parameters in ShapeLogic v 1.1

Tweaking the parameters is a little clumsy, currently this has be done from within the Java code.

Copy the following text into a file called CustomParticleCounter_.java:

import org.shapelogic.imageprocessing.BaseParticleCounter;
import org.shapelogic.imageutil.PlugInFilterAdapter;

/** CustomParticleCounter shows how customize the parameter settings. */
public class CustomParticleCounter_ extends PlugInFilterAdapter {
        
        public CustomParticleCounter_() {
                super(new BaseParticleCounter() {
            {
                _iterations = 4; // K-mean interations for color hypothesis
                _maxDistance = 90; // Distance between color in same color bucket
                _minPixelsInArea = 70; // Minimum number of pixels in particle
            }
        });
        }
}

Compile from within ImageJ

  • Place the CustomParticleCounter_.java into ImageJ/plugin/shapelogic directory.
  • Compile it from within ImageJ, by going to Plugin -> Compile and Run ...

Compile from outside ImageJ

  • Compile CustomParticleCounter_.java someplace else using Eclipse, NetBeans or javac and take the resulting 2 class files:

    CustomParticleCounter.class CustomParticleCounter_$1.class

  • Move them into ImageJ/plugin/shapelogic directory.

Plans for particle counter beyond ShapeLogic v 1.2

  • Reasoning under uncertainty using the lazy stream library
  • Later finding overlapping particles and counting them separately