roimanager: delete all ROIs not selected

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

roimanager: delete all ROIs not selected

Emanuele Martini
Hi to all,
I've a maybe simple question but i didn't find a quick solution, there is a way to automatically (in a script, or java/jython plugin) delete all NOT selected rois from roimanager?
Or i have to implement a for cycle for each roi present and check if there are selected?

Even a simple command like "invert roi selections" could be fine to my purpose.
Thank you,
Emanuele Martini
Image Analyst @Ifom-IEO research campus -MI-
Reply | Threaded
Open this post in threaded view
|

Re: roimanager: delete all ROIs not selected

Rasband, Wayne (NIH/NIMH) [E]
> On Mar 20, 2015, at 2:46 PM, Emanuele Martini <[hidden email]> wrote:
>
> Hi to all,
> I've a maybe simple question but i didn't find a quick solution, there is a
> way to automatically (in a script, or java/jython plugin) delete all NOT
> selected rois from roimanager?
> Or i have to implement a for cycle for each roi present and check if there
> are selected?

The following JavaScript code deletes all not selected ROIs from the ROI Manager. It requires ImageJ 1.49p or later.

-wayne

  rm = RoiManager.getInstance();
  indexes = new Array();
  index=0;
  for (i=0; i<rm.getCount(); i++) {
     if (!rm.isSelected(i))
        indexes[index++] = i;
  }
  rm.setSelectedIndexes(indexes);
  rm.runCommand("deleteā€);


> --
> View this message in context: http://imagej.1557.x6.nabble.com/roimanager-delete-all-ROIs-not-selected-tp5012100.html
> Sent from the ImageJ mailing list archive at Nabble.com.



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: roimanager: delete all ROIs not selected

Emanuele Martini
Thank you Wayne,
I resolved it this way via jython:
    idx_sel=roim.getSelectedIndex()
    roi_idxs=range(roim.count)
    del roi_idxs[idx_sel]
    roim.setSelectedIndexes(roi_idxs)
    roim.runCommand("Delete")

Thank you,
Have a nice day,
Emanuele
Image Analyst @Ifom-IEO research campus -MI-