How to replace a ROI in the RoiManager

imagej
roimanager

#1

Hi there,

We are working on making app for physician to calculate parameters in scintigraphy images.

We are using the RoiManager to store all ROI drawn by the phyiscian.

We met an issue that are limiting our developpement. We want to replace a defined ROI in the ROI manager by new coordinates.

We know about the “Update” function but it doesn’t fit for us because it require that the ROI to be the current ROI to update it while we need to do that programmatically (example : if the user change geometry of the current ROI number 2 we need to update the ROI 4 coordinate internally without any display)

We are looking for a “Replace” or a “SetROI” function that will put a ROI object in a particular position in the ROI manager (which will override an existing position).

Is there any way to achieve this ?

Best regards,

Salim


#2

Hi Salim,

I suggest another solution to this problem.
How about use the Class, Overlay?
And you can set overlay to RoiManager, if you want to use RoiManager after change something.

hwada


#3

Dear hwada,
I don’t see how it can solve my problem.
I do not have problem to generate the ROI object that I want to put in the RoiManager.
The problem is that I want to put this ROI to a specific position in the RoiManager (and override a previsouly defined ROI).

If I generate an Overlay I will still have the same problem to not be able to replace an existing ROI, the add overlay or ROI create a new entry in the RoiManager while I need a replace.

Best regards,

Salim


#4

Hi Salim,

How about like this?(these are not perfect code,)

  • Unfortunately, I have not use RoiManager for my plugins.

ImagePlus currentImage;
RaiManager manager;

Roi currentRoi = currentImage.getRoi.clone();
int index = manager.getRoiIndex(currentRoi); or getSelectedIndex();
*or Roi currentRoi = manager.getRoi(index).clone;
Roi rois = manager.getRoisAsArray();
rois[index] = currentRoi;
mangager.reset();
for(int i = 0; i < rois.length; i++){
manager.add(rois[i]);
//*and add the specific position currentRoi using “if”
}

However, I had create Overlay extended class to solve this like problem.
I added some methods, like these,getIndex(Roi), setRoi(int index)…and I changed Vector to ArrayList for sort methods.

hwada


#5

Thanks it could be a way to reset the ROI manager and re-add all ROIs.
It a bit ugly in our code because we will call this many time and it’s a bit wired to flush and rebuilt the ROI manager each time.
It’s kind of replacing the ROI manager internally in our code…

I just will wait for @Wayne opinion, if we should use your suggestion or if it possible to get a “replace” function in the Roi manager.

Thanks again for your help, it did help !


#6

I am glad that your purpose is realized.
I am wondering why the Overlay and RoiManager do not have the replace function too.


#7

The latest ImageJ daily build (1.52a58) adds an RoiManager.setRoi(roi,index) method. Here is a JavaScript example:

  rm = RoiManager.getInstance();
  if (rm==null) rm = new RoiManager();
  rm.reset();
  rm.addRoi(new OvalRoi(50,50,150,150));
  rm.addRoi(new OvalRoi(170,170,150,150));
  rm.addRoi(new OvalRoi(290,290,150,150));
  img = IJ.createImage("Untitled", "8-bit black", 500, 500, 1);
  img.show();
  rm.runCommand(img,"Show All with labels");
  IJ.wait(2000);
  roi = new Roi(190,190,110,110);
  rm.setRoi(roi, 1);

#8

Thank you so much @Wayne for your support and your help,
It is truly appreciated !