Login  Register

Re: Deleting an ROI by clicking on it

Posted by Krs5 on May 10, 2014; 10:20am
URL: http://imagej.273.s1.nabble.com/Deleting-an-ROI-by-clicking-on-it-tp5007671p5007673.html

Dear James,

Nice thought. I created a macro that will delete a ROI when you select it in an image. It also deletes it from the ROI manager.

If you would like some other info/action about the selected ROI, like ROI name you can add or change/add the code: roiManager("Delete"); (if more than one line put between {})


// This macro allows the user to left mouse-click on a ROI name
// in the image what will delete the ROI from the image and ROI manager.
// An image and the ROI manager have to be open to run the macro.
// You can add ROIs to an existing list in the ROI manager while the macro runs.
// Used as starting point the GetCursorLocDemo macro.
// The macro stops running when the "Log" window is closed.
// Kees Straatman, University of Leicester, 10 May 2014
macro DeleteSelected_ROI{
 if (nImages==0) exit("There is no image open");
 if (!isOpen("ROI Manager")) exit("There in no ROI manager open");
 if (roiManager("count")==0) exit("There are no ROIs loaded in the ROI manager");
 roiManager("Associate", "true");
 roiManager("Centered", "false");
 roiManager("UseNames", "true");
 setTool("rectangle");
 roiManager("Show All with labels");
 roiManager("Show All");
 roiManager("Deselect");
 leftButton=16;
 x2=-1; y2=-1; z2=-1; flags2=-1;
 logOpened = false;
 print("Close this window when finished");
 while (!logOpened || isOpen("Log")) {
  getCursorLoc(x, y, z, flags);
  if (x!=x2 || y!=y2 || z!=z2 || flags!=flags2) {  // Only when mouse moves new locatation is logged
  wait(20);      // Might have to be increased with large number of ROIs
               if (flags&leftButton!=0) {
    if (roiManager("index")!=-1)  // Check that a ROI is selected
     roiManager("Delete");
    }
               logOpened = true;
    }
           x2=x; y2=y; z2=z; flags2=flags;    // Only when mouse moves new location is logged
           wait(10);
      // Takes care that one mouse click is recorded as one mouse click
      }
}
---------------------------------------------------------------
Did some quick testing and it seems to work.

Kees

Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre of Core Techno
logy Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif



________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of Jmuller [[hidden email]]
Sent: 09 May 2014 19:52
To: [hidden email]
Subject: Deleting an ROI by clicking on it

Hi,

I am interested in a macro or plugin that will either let me record an ROI
ID number or delete it by clicking on it. Is any one aware of a tool like
this that might currently exist?

The reason I need this functionality is that I am doing some semi automated
image analysis by making a mask of immunofluorescently labeled cells and
then measuring the intensity for each cell in each channel from the ROI
manager. I generally have 10-15 conditions and take 9*9 tile images that
contain 300+ cells.

So far I can get about 85-90% accuracy of correctly outlining the cell and
excluding cells that are touching by using a combination of circularity,
water shedding and size exclusion. However, it still requires manually going
through each image and then writing down the bad ROI and then I have a
python script that will delete then from the results file. If I could record
the ROI just by clicking on them in imageJ this would really speed up my
image analysis and I think provide a sufficient level of automation with a
high level of accuracy.

Any help would be greatly appreciated,

Thanks,

James Muller



--
View this message in context: http://imagej.1557.x6.nabble.com/Deleting-an-ROI-by-clicking-on-it-tp5007671.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html