Classifying by color and shape

I would like to classify colonies by color and shape with ImageJ. Is there anybody how can tell how to do this?
The objects are round and often white, other objects are yellow.

Actually I use the “Particle analyze” but this works only with a binary picture and so I loose the color information.
Can anybody help me?
Thank you.

To classify by color, you might try thresholding by hue and saturation (user guide).

You should be able to find one setting that gives you only yellow colonies, and another that gives only the white ones.

Hope this helps.

1 Like

Hi @orguj

I’ve used jython scripting for color segmentation. Typically I first transform the image to a color space like LAB. Often times, all the objects can be found in the “intensity like” channel (lightness in LAB) . In these cases I apply thresholding and the paritcle analyzer to the “L” channel. I then perform a second step, where for each particle, I look at the mean intensity of the other channels (a and b in LAB), and classify particles based on this information. An example script and image are attached (by no means perfect, my example just shows the mechanics of performing this task, I did not optimize parameters (best threshold method, a, b, values to use for classification)).

p.s. I copied some of the code from here jython help

from ij import IJ
from ij.plugin import SubstackMaker
from ij.plugin.frame import RoiManager;
from ij.plugin.filter import ParticleAnalyzer
from ij.measure import Measurements
from java.lang import Double

imp=IJ.getImage()

# to lab color space
IJ.run(imp, "RGB to CIELAB", "");
imp=IJ.getImage()

# extract L, a, and b channels
substackMaker=SubstackMaker();
L=substackMaker.makeSubstack(imp, "1-1")
L.show()
a=substackMaker.makeSubstack(imp, "2-2")
a.show()
b=substackMaker.makeSubstack(imp, "3-3")
b.show()

# convert to 8 bit and threshold
IJ.run(L, "8-bit", "");
IJ.run(L, "Auto Threshold", "method=Default white");

# call roi manager 
roim = RoiManager(True)
pa = ParticleAnalyzer(ParticleAnalyzer.ADD_TO_MANAGER, Measurements.AREA, None, 0, Double.POSITIVE_INFINITY, 0.0, 1.0)
pa.setRoiManager(roim)
 
pa.analyze(L)

class1=[]
class2=[]

# loop through ROIs
for roi in roim.getRoisAsArray():
    a.setRoi(roi)
    b.setRoi(roi)

    # take a look at mean in a and b channel
    a_mean=a.getStatistics().mean
    b_mean=b.getStatistics().mean

    print a_mean,b_mean

    # add particles to either class 1 or 2 based on some criteria...
    if ( (a_mean>0) & (b_mean>0)):
        class1.append(roi)
    elif (a_mean>0):
        class2.append(roi)

print 
print "number ROIs of each class"
print len(class1)
print len(class2)
1 Like