Deleting an ROI by clicking on it

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

Deleting an ROI by clicking on it

Jmuller
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
Reply | Threaded
Open this post in threaded view
|

Re: Deleting an ROI by clicking on it

Krs5
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
Reply | Threaded
Open this post in threaded view
|

Re: Deleting an ROI by clicking on it

Krs5
In reply to this post by Jmuller
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
Reply | Threaded
Open this post in threaded view
|

Bug (I guess) after update of ImageJ or Java

CARL Philippe (LBP)
Dear all,
I had contributed some months ago on the update of the plot.java code in
order to extend the class for log-log, vector,... representations.
And since a recent update (I guess either of ImageJ or Java) the example
plugin:
http://imagej.nih.gov/ij/plugins/example-plots/index.html
and macro:
http://imagej.nih.gov/ij/macros/examples/LogLogPlot.txt
are not anymore working correctly.
Namely the graph grids, units and lines generated with
"Plot.drawNormalizedLine" are not anymore drawn (see plugin example picture
@ http://imagej.nih.gov/ij/plugins/example-plots/index.html).
Given that I'm afraid that the issue is way beyond my coding knowledge some
help on this issue would be very welcome.
Thanks a lot in advance.
My best regards,
Philippe

Philippe CARL
Laboratoire de Biophotonique et Pharmacologie
UMR 7213 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

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

Re: Bug (I guess) after update of ImageJ or Java

CARL Philippe (LBP)
Dear Michael,
Your idea was indeed the answer...
I was convinced that the problem was way more serious, this is why I looked
in the wrong direction...
Thanks a lot for your help and have a nice day,
Philippe

-----Message d'origine-----
De : Michael Schmid [mailto:[hidden email]]
Envoyé : lundi 12 mai 2014 12:21
À : Philippe CARL
Cc : Michael Schmid
Objet : Re: Bug (I guess) after update of ImageJ or Java

Hi Philippe,

off-list, I am not sure whether this is the real answer.

On my computer, it works well with ImageJ 1.48v.
Are you sure that your settings in Edit>Options>Profile Plot Options are ok?

Michael
________________________________________________________________
Michael Schmid                    email: [hidden email]
Institut für Angewandte Physik, Technische Universität Wien Wiedner
Hauptstr. 8-10/E134, A 1040 Wien, Austria Tel. +43 1 58801-13452 or -13453,
Fax +43 1 58801 13499
________________________________________________________________

On May 12, 2014, at 11:38, Philippe CARL wrote:

> Dear all,
> I had contributed some months ago on the update of the plot.java code
> in order to extend the class for log-log, vector,... representations.
> And since a recent update (I guess either of ImageJ or Java) the
> example
> plugin:
> http://imagej.nih.gov/ij/plugins/example-plots/index.html
> and macro:
> http://imagej.nih.gov/ij/macros/examples/LogLogPlot.txt
> are not anymore working correctly.
> Namely the graph grids, units and lines generated with
> "Plot.drawNormalizedLine" are not anymore drawn (see plugin example
> picture @ http://imagej.nih.gov/ij/plugins/example-plots/index.html).
> Given that I'm afraid that the issue is way beyond my coding knowledge
> some help on this issue would be very welcome.
> Thanks a lot in advance.
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Biophotonique et Pharmacologie UMR 7213 CNRS -
> Université de Strasbourg Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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