Jaccard index for checking segmentation accuracy

Hi Can anyone pl. tell How to find Jaccard index between two images in imagej Thank You.

1 Like

Essentially, you can:

  • use the image calculator (Process › Image Calculator…) to create an intersection (AND) image and a union (OR) image, then
  • measure their respective integrated density (using Analyze › Set Measurements… and Analyze › Measure) and divide the resulting values

to create an Intersection over Union quotient (i.e. the Jaccard index).

Here’s a small Groovy script that does this (run it from the script editor after selecting Language › Groovy):

#@ ImagePlus imp1
#@ ImagePlus imp2
#@output IoU

import ij.plugin.ImageCalculator
import ij.measure.Measurements

intersect = ImageCalculator.run(imp1, imp2, "and create")
union = ImageCalculator.run(imp1, imp2, "or create")

i = intersect.getStatistics(Measurements.INTEGRATED_DENSITY)
u = union.getStatistics(Measurements.INTEGRATED_DENSITY)
IoU = (i.area * i.mean) / (u.area * u.mean)
6 Likes

Hi @Arunak ,

if you use the clij Fiji plugin by chance, you can also compute the Jaccard index like this:

Ext.CLIJ2_getJaccardIndex(mask1, mask2, jaccardIndex);

// output result
print("Overlap (Jaccard index): " + (jaccardIndex*100) + "%");

You find a complete example macro here.

Let us know if this helps :slightly_smiling_face:

Cheers,
Robert

5 Likes

Thank you so much!! very clear steps, checked it its working…

Thank you so much for this info will check out soon!!