Starting in 1.2 ShapeLogic contains both an automatic color and gray scale particle counter and a particle analyzer working without manual user intervention. The goal is to be able to recognize different cells on a relatively uniform background and be able to extract a lot of geometric information.
See Cell Categorizer for images types that can be handled by the current particle analyzer, and for future plans.
ShapeLogic 1.3 introduced 2 new modes for the particle analyzer: one where you set the foreground color of the particles and one where you set the background color. They will always find a particle image and will not fail, unlike the automatic particle analyzer.
ShapeLogic 1.5 introduced neural network machine learning.
Test on example particle image embryos.jpg
Under ImageJ Plugins ShapeLogic menu click "Particle Counter", "Color Particle Analyzer" or "RGB Color Particle Analyzer".
Select input parameters in dialog
The parameters
Max distance: Distance between color in same color bucket
Min pixels: Minimum number of pixels in particle
Max pixels: Maximum number of pixels in particle
Iterations: K-mean iterations for color hypothesis
CountOnly: Only count particles, do not trace edge, vectorize, annotate and match
ToMask: Turns the image into a black and white mask, with black particles
DisplayInternalInfo: Print out polygon, points and their annotations
UseNeuralNetwork: Use neural network for classification
These are the default values and the name of the parameters in Java.
_iterations = 2; // K-mean iterations for color hypothesis _maxDistance = 50; // Distance between color in same color bucket _minPixelsInArea = 5; // Minimum number of pixels in particle _maxPixelsInArea = 10000; // Maximum number of pixels in particle
Check ToMask check box in order to better see what particles were found and to post process it with other tools. The built in particle analyzer in ImageJ contains functionality that is not available here e.g.
Here is the result of running outline and add numbers
The numbering scheme used in ImageJ particle analyzer is the same as the one used in ShapeLogic. Start from top left corner.
A summary result is shown in a dialog, with the following information:
A report of each particle's properties is sent to an ImageJ result table, which can be exported to Excel. Reports are different for the particle counter and analyzer.
The particle counter finds and prints basic geometric properties of the particles
The particle analyzer traces the edge of each particle. It finds and prints more advanced geometric properties of the particles
For color images it will also write out average R, G and B channels.
The particle analyzer finds many more geometric properties that are not shown on the above example, it is easy to print them if desired.
This the particle analyzer can also select and categorize particles based on all of the above properties. In order to categorize particles the user should define geometric rules for each particle type.
ShapeLogic v 1.6 will come with predefined rules to categorize certain cells .
If you want more detailed information mark check box DisplayInternalInfo.
ShapeLogic 1.3 introduces 2 new color modes for the particle analyzer.
You find them under the menu item: RGB Color Particle Analyzer.
One will set the background color the other sets the foreground color.
This is useful for
Here is an example
CDC image 10157 legionella pneumophila
The setting in the dialog was to find the purple bacteria.
This is useful for
The particle analyzer in ShapeLogic v 1.5 has gone through limited testing and seems to work well.
The particle counter algorithm in ShapeLogic 1.5 is relatively simple. It is setup to be expanded to handle more advanced algorithms. Here is the flow.
This is done by sub classing ColorParticleAnalyzer or ColorParticleAnalyzerIJ. Override the categorizeStreams() method.
Use ColorParticleAnalyzerIJ if you work with ImageJ and ColorParticleAnalyzer if you work without.
Here is the current categorize code. It is only there to serve as an example:
The rule syntax is very straightforward. There are a lot of numeric streams with one lazy calculated number for each particle. E.g. aspect ratio stream. Then you define one rule for each constraint you want to put on a given category.
In order to belong to the category Flat the aspect ratio for a particle just has to greater than 1.1.
In order to belong to the category "Light round" the aspect ratio for a particle just has to between 0.9 and 1.1 and the brightness have to be greater than 150.
Note that a particle that satisfy more categories will not belong to any of them.
@Override protected void categorizeStreams() { loadParticleStreams.exampleMakeParticleStream(); if (_useNeuralNetwork) { defineNeuralNetwork(); } else { loadLetterStreams.makeXOrStream(StreamNames.PARTICLES, LoadParticleStreams.EXAMPLE_PARTICLE_ARRAY); _categorizer = (ListStream<String>) QueryCalc.getInstance().get(StreamNames.PARTICLES, this); } } private void defineNeuralNetwork() { String[] objectHypotheses = new String[] {"Tall", "Flat"}; String[] inputStreamName = {StreamNames.ASPECT}; double[][] weights = ExampleNeuralNetwork.makeSmallerThanGreaterThanNeuralNetwork(1.); _neuralNetworkStream = new FFNeuralNetworkStream( inputStreamName,objectHypotheses, weights,this); _categorizer = _neuralNetworkStream.getOutputStream(); } final static public String[] EXAMPLE_PARTICLE_ARRAY = {"Flat","Tall","Light round", "Dark round"}; /** This shows what to do to define rules for the color particle analyzer.<br /> * * This is not useful.<br /> * Light and dark is turned around if inverted LUT is used.<br /> */ public static void exampleMakeParticleStream() { LoadLetterStreams.rule("Flat", ASPECT_RATIO, ">", 1.1, null); LoadLetterStreams.rule("Tall", ASPECT_RATIO, "<", 0.9, null); LoadLetterStreams.rule("Light round", StreamNames.COLOR_GRAY, ">", 150, null); LoadLetterStreams.rule("Light round", ASPECT_RATIO, "<", 1.1, null); LoadLetterStreams.rule("Light round", ASPECT_RATIO, ">", 0.9, null); LoadLetterStreams.rule("Dark round", StreamNames.COLOR_GRAY, "<", 120, null); LoadLetterStreams.rule("Dark round", ASPECT_RATIO, "<", 1.1, null); LoadLetterStreams.rule("Dark round", ASPECT_RATIO, ">", 0.9, null); }
Currently you have to override categorizeStreams() to customize neural network or rule set, this will be re factored so there are 2 protected methods that can be overridden:
Here is a very simple example that overrides both the declarative rule set and the neural network:
This example only has 2 categories Flat and Non flat. It is flat if it twice as wide as it is high.
This example only has 2 categories Light and Dark.
Link to neural network and machine learning .
Copy the following text into a file called CustomParticleAnalyzer_.java:
import org.shapelogic.imageprocessing.ColorParticleAnalyzerIJ; import org.shapelogic.logic.CommonLogicExpressions; import org.shapelogic.machinelearning.ExampleNeuralNetwork; import org.shapelogic.machinelearning.FFNeuralNetworkStream; import org.shapelogic.streamlogic.LoadLetterStreams; import org.shapelogic.streamlogic.StreamNames; import org.shapelogic.streams.XOrListStream; public class CustomParticleAnalyzer_ extends ColorParticleAnalyzerIJ { @Override protected void categorizeStreams() { loadParticleStreams.exampleMakeParticleStream(); if (_useNeuralNetwork) { //----------Override neural network---------- String[] objectHypotheses = new String[] {"Dark", "Light"}; String[] inputStreamName = {StreamNames.COLOR_GRAY}; double[][] weights = ExampleNeuralNetwork.makeSmallerThanGreaterThanNeuralNetwork(128.); _neuralNetworkStream = new FFNeuralNetworkStream( inputStreamName,objectHypotheses, weights,this); _categorizer = _neuralNetworkStream.getOutputStream(); } else { // //----------Override declarative rule set---------- LoadLetterStreams loadLetterStreams = new LoadLetterStreams(this); loadLetterStreams.rule("Flat", CommonLogicExpressions.ASPECT_RATIO, ">", 2, null); loadLetterStreams.rule("Non flat", CommonLogicExpressions.ASPECT_RATIO, "<", 2, null); loadLetterStreams.makeXOrStream(StreamNames.PARTICLES, new String[] {"Flat", "Non flat"}); _categorizer = (XOrListStream) getContext().get(StreamNames.PARTICLES); } } }
CustomParticleAnalyzer_.class
In order to do this the user will have to select the properties that should be used to train the network or use the machine learning on.
It is probably easiest to export all the properties to a spreadsheet, add a result field, and run an external neural network or machine learning program. The result will then be put back into a ShapeLogic stream.
Right now the classifier stream is an Exclusive Or stream. There need to be streams that