Opening multiple ROIs and adjusting them all at once...

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

Opening multiple ROIs and adjusting them all at once...

Jacqueline Ross
Dear All,

I would like to be able to add multiple ROIs to an image, see them all at
once but still be able to click on each one and move it independently.

What we need to be able to do is save a set of ROIs (5 circular regions)
and load them onto multiple images. However, we then need to adjust their
positions in relation to each other & it's hard to do this when you can
only see one at a time.

We don't want to combine the ROIs because we need separate measurements for
each ROI. Also, if you combine them, then they all move as one.

I looked in the archives and found a similar question posed in 2003 with
the subject line as above but no reply.

Can anyone help me with this? It's quite possible that I'm missing
something and that this is possible with the updated version of ImageJ
which I noticed has some additional tools in the ROI manager.
Reply | Threaded
Open this post in threaded view
|

Re: Opening multiple ROIs and adjusting them all at once...

Greg Joss
The following may assist with what you wish.
It adds a non-destructive graphic overlay of all (area) rois from
RoiManager to an image.
It will overwrite the current selection but the roi point markers are
still visible.
You can move the currently active roi, update in RoiManager and
redisplay.
//__________________________________________________________
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.*;
import ij.gui.*;
import ij.process.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;

/** This plugin is an extension of Wayne Rasband's example showing how
to add a non-destructive
      graphic overlay to an image or stack.
It overlays all area rois from RoiManager  [hidden email] 13/9/06

it doesnt cater for all PathIterator  segment types but should work for
circles, PolygonRois
*/
public class RoiSet_Overlay implements PlugIn {
   Hashtable rois;
    public void run(String arg) {
        ImagePlus imp = IJ.getImage();
            RoiManager rm=RoiManager.getInstance();
            if(rm==null){
                IJ.error("RoiSet_Overlay requested but no
roiManager");
                return;
            }
  rois=rm.getROIs();
/*
            for (Enumeration e = rois.keys(); e.hasMoreElements() ;) {
              String label=(String)e.nextElement();
          Roi roi = (Roi)rois.get(label);
          IJ.log("["+label+" "+roi.isArea()+")"+roi);
          imp.setRoi(roi);
              IJ.run("Draw");
        }
*/
        CustomCanvas cc = new CustomCanvas(imp);
        if (imp.getStackSize()>1)
            new StackWindow(imp, cc);
        else
           new ImageWindow(imp, cc);
    }

    class CustomCanvas extends ImageCanvas {
   
        CustomCanvas(ImagePlus imp) {
            super(imp);
        }

        public void paint(Graphics g) {
            super.paint(g);
            drawOverlay(g);
         }

        void drawOverlay(Graphics g) {
            g.setColor(Color.red);
            for (Enumeration e = rois.keys(); e.hasMoreElements() ;) {
                String label=(String)e.nextElement();
                Roi roi = (Roi)rois.get(label);
        // if(roi.isArea()){
                        Polygon p=roi.getPolygon();
                        PathIterator pi=p.getPathIterator(null);
                        int nc=0;
                        float[] xys=new float[6];
                        int xn=0,yn=0,xp=0,yp=0,xi=0,yi=0;
                        int ct=0;
                        while(!pi.isDone()){
                                ct=pi.currentSegment(xys);
                                xn=screenX(Math.round(xys[0]));
                                yn=screenY(Math.round(xys[1]));
                                if(nc==0){xi=xn;yi=yn;}
                                else g.drawLine(xp,yp,xn,yn);
                                xp=xn;yp=yn;
                                pi.next();
                                nc++;
                        }
  if(ct==pi.SEG_CLOSE)g.drawLine(xn,yn,xi,yi);
        // }
        }
       }
   
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            //IJ.log("mousePressed:
("+offScreenX(e.getX())+","+offScreenY(e.getY())+")");
        }
   
    } // CustomCanvas inner class
}
//__________________________________________________________

--
Greg Joss,
Department of Biological Sciences, Phone: (61)(2) 9850 8212 Fax: 9850
8245
Macquarie University,              Email: [hidden email]
North Ryde, (Sydney,) NSW 2109, Australia


>>> [hidden email] 09/12/06 11:19 am >>>
Dear All,

I would like to be able to add multiple ROIs to an image, see them all
at
once but still be able to click on each one and move it independently.

What we need to be able to do is save a set of ROIs (5 circular
regions)
and load them onto multiple images. However, we then need to adjust
their
positions in relation to each other & it's hard to do this when you can

only see one at a time.

We don't want to combine the ROIs because we need separate measurements
for
each ROI. Also, if you combine them, then they all move as one.

I looked in the archives and found a similar question posed in 2003
with
the subject line as above but no reply.

Can anyone help me with this? It's quite possible that I'm missing
something and that this is possible with the updated version of ImageJ

which I noticed has some additional tools in the ROI manager.
Reply | Threaded
Open this post in threaded view
|

Re: Opening multiple ROIs and adjusting them all at once...

Jacqueline Ross
In reply to this post by Jacqueline Ross
Dear Greg,

Thanks very much for your reply and for the plugin. With a bit of
assistance from a friend, we managed to get it working and it's just
what I needed.

It's a valuable addition to ImageJ for working with multiple ROIs.

Cheers,

Jacqui.

Jacqueline Ross
Biomedical Imaging Research Unit
School of Medical Sciences
Faculty of Medical & Health Sciences
The University of Auckland
Private Bag 92019
Auckland, NEW ZEALAND

Tel: 64 9 373 7599 Ext 87438
Fax: 64 9 373 7484

http://www.health.auckland.ac.nz/biru/ 

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
Greg Joss
Sent: 13 September 2006 16:31
To: [hidden email]
Subject: Re: Opening multiple ROIs and adjusting them all at once...

The following may assist with what you wish.
It adds a non-destructive graphic overlay of all (area) rois from
RoiManager to an image.
It will overwrite the current selection but the roi point markers are
still visible.
You can move the currently active roi, update in RoiManager and
redisplay.
//__________________________________________________________
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.*;
import ij.gui.*;
import ij.process.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;

/** This plugin is an extension of Wayne Rasband's example showing how
to add a non-destructive
      graphic overlay to an image or stack.
It overlays all area rois from RoiManager  [hidden email] 13/9/06

it doesnt cater for all PathIterator  segment types but should work for
circles, PolygonRois
*/
public class RoiSet_Overlay implements PlugIn {
   Hashtable rois;
    public void run(String arg) {
        ImagePlus imp = IJ.getImage();
            RoiManager rm=RoiManager.getInstance();
            if(rm==null){
                IJ.error("RoiSet_Overlay requested but no
roiManager");
                return;
            }
  rois=rm.getROIs();
/*
            for (Enumeration e = rois.keys(); e.hasMoreElements() ;) {
              String label=(String)e.nextElement();
          Roi roi = (Roi)rois.get(label);
          IJ.log("["+label+" "+roi.isArea()+")"+roi);
          imp.setRoi(roi);
              IJ.run("Draw");
        }
*/
        CustomCanvas cc = new CustomCanvas(imp);
        if (imp.getStackSize()>1)
            new StackWindow(imp, cc);
        else
           new ImageWindow(imp, cc);
    }

    class CustomCanvas extends ImageCanvas {
   
        CustomCanvas(ImagePlus imp) {
            super(imp);
        }

        public void paint(Graphics g) {
            super.paint(g);
            drawOverlay(g);
         }

        void drawOverlay(Graphics g) {
            g.setColor(Color.red);
            for (Enumeration e = rois.keys(); e.hasMoreElements() ;) {
                String label=(String)e.nextElement();
                Roi roi = (Roi)rois.get(label);
        // if(roi.isArea()){
                        Polygon p=roi.getPolygon();
                        PathIterator pi=p.getPathIterator(null);
                        int nc=0;
                        float[] xys=new float[6];
                        int xn=0,yn=0,xp=0,yp=0,xi=0,yi=0;
                        int ct=0;
                        while(!pi.isDone()){
                                ct=pi.currentSegment(xys);
                                xn=screenX(Math.round(xys[0]));
                                yn=screenY(Math.round(xys[1]));
                                if(nc==0){xi=xn;yi=yn;}
                                else g.drawLine(xp,yp,xn,yn);
                                xp=xn;yp=yn;
                                pi.next();
                                nc++;
                        }
  if(ct==pi.SEG_CLOSE)g.drawLine(xn,yn,xi,yi);
        // }
        }
       }
   
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            //IJ.log("mousePressed:
("+offScreenX(e.getX())+","+offScreenY(e.getY())+")");
        }
   
    } // CustomCanvas inner class
}
//__________________________________________________________

--
Greg Joss,
Department of Biological Sciences, Phone: (61)(2) 9850 8212 Fax: 9850
8245
Macquarie University,              Email: [hidden email]
North Ryde, (Sydney,) NSW 2109, Australia


>>> [hidden email] 09/12/06 11:19 am >>>
Dear All,

I would like to be able to add multiple ROIs to an image, see them all
at
once but still be able to click on each one and move it independently.

What we need to be able to do is save a set of ROIs (5 circular
regions)
and load them onto multiple images. However, we then need to adjust
their
positions in relation to each other & it's hard to do this when you can

only see one at a time.

We don't want to combine the ROIs because we need separate measurements
for
each ROI. Also, if you combine them, then they all move as one.

I looked in the archives and found a similar question posed in 2003
with
the subject line as above but no reply.

Can anyone help me with this? It's quite possible that I'm missing
something and that this is possible with the updated version of ImageJ

which I noticed has some additional tools in the ROI manager.