Login  Register

Re: Deleting an ROI by clicking on it

Posted by Krs5 on May 12, 2014; 8:47am
URL: http://imagej.273.s1.nabble.com/Deleting-an-ROI-by-clicking-on-it-tp5007671p5007689.html

Dear James,

After some further thinking and playing with code over the weekend I have now a macro that will delete the ROI from the image, ROI manger and the row in the Results table. For this to work the results table has to be created using
the Multi Measure option (deselect "One Row Per Slice") from the ROI Managers menu with "Display label" selected in Set Measurements.

The macro can also be downloaded from: https://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif/software-1/imagej-macros 

// This macro allows the user to left mouse-click on a ROI name
// in the image what will delete the ROI from the image, ROI manager
// and results table.
// For this to work the results table has to be created using
// the Multi Measure option (deselect "One Row Per Slice") from the
// ROI Managers menu with "Display label" selected in Set Measurements
// (Analyze > Set Measurements).

// Used as starting point the GetCursorLocDemo macro.
// The macro stops running when the "Log" window is closed.
// Kees Straatman, University of Leicester, 12 May 2014

macro DeleteSelected_ROI2{
        if (nImages==0) exit("There is no image open");
        if (!isOpen("ROI Manager")) exit("There is no ROI manager open");
        if (!isOpen("Results")) exit("There is no results table. Create via Multi Measure option in ROI Manager");
        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) {
              // Check that a ROI is selected
                                if (roiManager("index")!=-1){
                                        RoiName= Roi.getName();
                                        del = false; // Becomes "true" when a result is deleted from the table
                                        selectWindow("Results");
                                        for (i=0;i<(roiManager("count"));i++){
                                                if (del==false){
                                                        // Check label ROI against labels in Results table
                                                        S = getResultLabel(i);
                                                        if (matches(S,".*"+RoiName+".*")){
                                                                IJ.deleteRows(i, i);
                                                                del = true;
                                                        }
                                                }
                                        }
                                        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
      }
        }
} ------------ end of code---------------------


Let me know if you encounter problems.

Best wishes

Kees


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


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Jmuller
Sent: 09 May 2014 19:53
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