Moving multiple ROIs at the same time

64 views
Skip to first unread message

louise-laure

unread,
Jul 25, 2014, 11:20:50 AM7/25/14
to icy-so...@googlegroups.com
Hello everyone,
for those who are not on vacation,

I manage to copy multiple ROIs at the same time and paste them to another sequence,
but
could you tell me if there is a way to move all the ROI on the image,

for instance if I want to make a translation on the right and up (= on the x and y axis) of all the ROIs at the same time I can't,
(and if I use the arrow on the keyboard for instance, it'll just move the frame to the next timeframe but not move my ROIs at all),

so how is it possible to select all ROI and move all of them ?


Idem, but maybe more tricky,
is it possible to change the z of all the ROIs at the same time,

let's say for instance, all my ROIs are on Z=5,
and I want to move them to Z= 13?

(I must say until now, I had to move all my ROIs one by one...
really a BIG PROBLEM...)

I have to do it because I've been trying to use a protocole with active meshes to track my cells over time but it's not working for now... ALex Dufour will help me later on that point

Thanks in advance for all your help
LL

Will Ouyang

unread,
Jul 29, 2014, 10:37:49 AM7/29/14
to icy-so...@googlegroups.com
Hi Louise,

I just write a script for you, see if it's what you want. Just type "moveAllSelectedROI" in the search bar of Icy, and wait for a moment, click the online script and it will install it automatically. See a short usage here:http://icy.bioimageanalysis.org/script/moveAllSelectedROI


And you can also paste the code manually, Here goest the js code:

//Move all selected roi together
//Usage
//Select all ROIs you want to move together
//run this script, and you will found a red point ROI on the left-top corner of current sequence
//drag the red point
 
 
//Author Will Ouyang
 
 
importClass(Packages.icy.type.collection.array.Array1DUtil)
importClass(Packages.icy.roi.ROIListener)
importClass(Packages.icy.roi.ROI2DPoint)
importClass(Packages.java.awt.geom.Point2D)
importClass(Packages.java.awt.Color)
importClass(Packages.java.util.HashMap)
seq = getSequence()
if (seq == null) throw "Please open a sequence first"
  
rois = seq.getROI2Ds()
if (rois.isEmpty()) throw "No ROI on the sequence"
roi = rois.get(0)
 
anchor = new ROI2DPoint(0,0)
anchor.setColor(Color.red)
seq.addROI(anchor, true)
lastPos = anchor.getPosition2D()
var pl = new HashMap()
size = rois.size()
for(i = 0;i< size ;i++ )
{
    roi = rois.get(i)
    if(roi.isSelected())
    if(roi != anchor)
    {
        pl.put(roi,roi.getPosition2D())
    }
}
anchor.setSelected(true)
anchor.addListener(new ROIListener(){
    roiChanged: function(ev) {
        anchor = ev.getSource()
        curPos =  anchor.getPosition2D()
        for(i = 0;i< size ;i++ )
        {
            roi = rois.get(i)
            if(roi == anchor)
                continue
            try
            {
                p = pl.get(roi)
                roi.setPosition(new Point2D.Double(p.getX()+curPos.getX(),p.getY()+curPos.getY()))
            }
            catch(e)
            {
            }
        }
        }
})

For you second task I think it easier to move it with some small modification, that is adding the following line to set position Z:

...
             try
            {
                p = pl.get(roi)
                roi.setPosition(new Point2D.Double(p.getX()+curPos.getX(),p.getY()+curPos.getY()))
                            roi.setZ(13)
            }
            catch(e)
            {
            }
...

I hope this can solve your problem. Good luck.



Paste the above code to ScriptEditor, and you can run it. I also submitted the script to icy repository, you can also  

louise-laure

unread,
Jul 30, 2014, 5:40:47 AM7/30/14
to icy-so...@googlegroups.com
Man!
That is super cool!
and exactly what I needed (for the x and y change, I guess the z must be difficult to do)

Thank you very much!
LL
    <code class="js plain" style="outline: 0px !important; font-size: 1em !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important;
...

louise-laure

unread,
Aug 4, 2014, 4:48:33 AM8/4/14
to icy-so...@googlegroups.com
Hey,
just asking one more stupid question,

I'm trying to use your script in a protocol,
is there anyway to use this script without having to pre "select the ROIs" before?

I tried adding // before if(roi.isSelected())
but it seems to need more rewriting than that!

Or is there an existing block in protocols to select ROIs?

Thanks again,
LL

Will Ouyang

unread,
Aug 4, 2014, 5:20:17 AM8/4/14
to icy-so...@googlegroups.com
Hi,

Could you give me more info about the context of what you are trying to do? Because the script I gave to you is for interacting in sequence viewer.


Best,
Will Ouyang


--
You received this message because you are subscribed to a topic in the Google Groups "Icy imaging" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/icy-software/49OI1VVhH5A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to icy-software...@googlegroups.com.
To post to this group, send email to icy-so...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/icy-software/c1c99528-f267-4f69-887e-9997e86cb43d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

louise-laure

unread,
Aug 4, 2014, 6:02:04 AM8/4/14
to icy-so...@googlegroups.com
Thanks!
indeed,
I used it as an interactive window initially,
but now I'm trying to merge these 2 protocols
with using your script in between those 2 to set a specific position for T and Z after protocol 1 and before protocol 2

(cf 2 attached files for protocols)

LL
Protocol 1.xml
Protocol2.xml

Will Ouyang

unread,
Aug 4, 2014, 7:04:50 AM8/4/14
to icy-so...@googlegroups.com
Hi,

You are welcome.

To do that, you need to add a Js block, and add an output with "List of roi" type, then use the following script:

size = input0.length
for(i=0;i<size;i++)
{
p = input0[i].getPosition5D()
//set z and t here
p.setZ(1);
p.setT(-1);
input0[i].setPosition5D(p)
}
output0 = input0

Here's my demonstration:

louise-laure

unread,
Aug 4, 2014, 9:40:00 AM8/4/14
to icy-so...@googlegroups.com
Works great thanks!
Reply all
Reply to author
Forward
0 new messages