Jython equivalent for Overlay.activateselection?

Based on the below example code, I am creating a python script equivalent, however I cannot find a similar action as Overlay.activateselection in the Overlay API (https://imagej.nih.gov/ij/developer/api/ij/gui/Overlay.html)

What I would like to do is to activate a particular overlay/ROI and then analyzed particles on that overlay/ROI.

  run("Blobs (25K)");
  setAutoThreshold("Default");
  run("Analyze Particles...", "  show=Overlay");
  Overlay.copy
  newImage("Untitled", "8-bit ramp", 256, 254, 1);
  Overlay.paste
  for (i=0; i<Overlay.size; i++) {
    Overlay.activateSelection(i);
    List.setMeasurements;
    mean = List.getValue("Mean");
    print(i+"  "+mean);
  }```

Hello Chris -

I think you have to do it in two steps: First retrieve the desired
Roi from the Overlay with Overlay.get(); and then apply
that Roi to your image with ImagePlus.setRoi().

Here is a demonstration jython script:

from ij import IJ
from ij.gui import Overlay
from ij.gui import Roi

imp = IJ.createImage ('overlays', '8-bit ramp', 256, 256, 1)

# make an overlay with three elements
ov = Overlay()
ov.add (Roi (10, 10, 10, 10))  # element 0
ov.add (Roi (30, 30, 30, 30))  # element 1
ov.add (Roi (70, 70, 70, 70))  # element 2

# equivalent to Overlay.activateSelection (1);
imp.setRoi (ov.get (1))

# display image with activated selection
imp.show()

Thanks, mm

2 Likes