Coloring nodes according to their tags in TraKEM2

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Coloring nodes according to their tags in TraKEM2

L'assegnista
Dear list,
Thank you for the very useful comments to my previous question! I'm here
with another one..
always on TraKEM2.

I'm tracing fibers bundles with treelines and using tags to annotate each
node based on the staining in another channel. To visualize the
distribution of tags in 3D I tried the function "color path between two
nodes tagged as" but I obtained strange results.
Does anyone can suggest a method (or a script) to color nodes according to
their tags?

Thank you

P.S. For Stephan, I don't know if I love the risky life, I just found that
manual tracing is a very inspiring way of losing time!


--
Federico Luzzati, PhD
Assistant Professor
University of Turin,
Dept. LIfe Sciences and Systems Biology (DBIOS)
Via Accademia Albertina, 13 - 10123 Torino - IT

Researcher at
Neuroscience Institute Cavalieri Ottolenghi (NICO)
Regione Gonzole, 10 - 10043 Orbassano (To) - IT

tel. +39-0116704683/ -6631
http://www.nico.ottolenghi.unito.it/index.php/it/adult-neurogenesis

Sostieni con il tuo 5xmille il NICO e la ricerca sulle malattie
neurodegenerative
Firma nel riquadro "Finanziamento della ricerca scientifica e
dell'Università"
CF 97564560015

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

controlling a macro tool with mouse events

Romain Penz
Dear all,

I guess I make a mistake when trying to use the flags (from getCursorLoc(x, y, z, flags)) to control the events of a macro tool I'm writing.

I want to left click on the starting point of a straight line roi I then draw dragging the mouse cursor. When the left click is released, and then click again I want to draw another straight line roi depending on the first one (perpendicular to it. That functionality will be added, adapting the code when the left click control is ok). The code below only permit to draw two straight lines roi.

The first step is ok. The problem is that the second step is ignored when running my macro. I think my code doesn't well react to the left click event.

Do you have an idea of what' wrong with my code? Is there a simplest way to control a macro depending on the left click?


macro "spores-X-shape Tool"{

 run("Line Width...", "line=1");

                leftButton=16;


getPixelSize(unit, pixelWidth, pixelHeight);

    getCursorLoc(x, y, z, flags);

  xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;

wasLeftPressed = false;

i=1;
while (i<3){

// first line

if (flags&leftButton==16 && wasLeftPressed==false){

        while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2){
                        //if (x!=x2 || y!=y2 ){
          makeLine(xstart, ystart, x, y);
          x2=x; y2=y;
          wait(10);
                        }


        }

roiManager("Add");
print("first line");
wasLeftPressed = true;
i=i+1;
}

//second line

if (flags&leftButton==16 && wasLeftPressed==true){

        getCursorLoc(x, y, z, flags);
        xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;


    while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2 || flags!=flags2){
                       
          makeLine(xstart, ystart, x, y);
          x2=x; y2=y;
          wait(10);
                        }


        }
wasLeftPressed = false;
roiManager("Add");
print("second line");
i=i+1;
}
}
}
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: controlling a macro tool with mouse events

Romain Penz
I found a piece of solution using the wait(1000) command. If I'm fast enough I can select the starting point of the second line during the wait(1000) command. But I hope there is another proper solution not depending on my ability to quick select the second line starting point.

Do you have any  idea? I've looked at the wait_for_user macro but having to click on the prompt window is not a solution (because it adds an undesired step).

here's the modified code with the wait() command between the pieces of code allowing to select the two straight lines :

macro "spores-X-shape Tool"{

 run("Line Width...", "line=1");

                leftButton=16;


getPixelSize(unit, pixelWidth, pixelHeight);

    getCursorLoc(x, y, z, flags);

        xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;

wasLeftPressed = false;

i=1;
while (i<3){

// first line

if (flags&leftButton==16 && wasLeftPressed==false){

        while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2){
                        //if (x!=x2 || y!=y2 ){
                        makeLine(xstart, ystart, x, y);
                        x2=x; y2=y;
                        wait(10);
                        }


        }

roiManager("Add");
print("first line");
wasLeftPressed = true;
i=i+1;
}

//second line

if (flags&leftButton==0 && wasLeftPressed==true){


wait(1000);

        getCursorLoc(x, y, z, flags);
        xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;


    while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2 || flags!=flags2){

                        makeLine(xstart, ystart, x, y);
                        x2=x; y2=y;
                        wait(10);
                        }


        }
wasLeftPressed = false;
roiManager("Add");
print("second line");
i=i+1;
}
}
}
________________________________________
De : ImageJ Interest Group <[hidden email]> de la part de Romain Penz <[hidden email]>
Envoyé : mardi 16 février 2016 17:21
À : [hidden email]
Objet : controlling a macro tool with mouse events

Dear all,

I guess I make a mistake when trying to use the flags (from getCursorLoc(x, y, z, flags)) to control the events of a macro tool I'm writing.

I want to left click on the starting point of a straight line roi I then draw dragging the mouse cursor. When the left click is released, and then click again I want to draw another straight line roi depending on the first one (perpendicular to it. That functionality will be added, adapting the code when the left click control is ok). The code below only permit to draw two straight lines roi.

The first step is ok. The problem is that the second step is ignored when running my macro. I think my code doesn't well react to the left click event.

Do you have an idea of what' wrong with my code? Is there a simplest way to control a macro depending on the left click?


macro "spores-X-shape Tool"{

 run("Line Width...", "line=1");

                leftButton=16;


getPixelSize(unit, pixelWidth, pixelHeight);

    getCursorLoc(x, y, z, flags);

        xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;

wasLeftPressed = false;

i=1;
while (i<3){

// first line

if (flags&leftButton==16 && wasLeftPressed==false){

        while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2){
                        //if (x!=x2 || y!=y2 ){
                        makeLine(xstart, ystart, x, y);
                        x2=x; y2=y;
                        wait(10);
                        }


        }

roiManager("Add");
print("first line");
wasLeftPressed = true;
i=i+1;
}

//second line

if (flags&leftButton==16 && wasLeftPressed==true){

        getCursorLoc(x, y, z, flags);
        xstart = x; ystart = y;
    x2=x; y2=y;
        flags2= flags;


    while (flags&leftButton==16){

                        getCursorLoc(x, y, z, flags);

                        if (x!=x2 || y!=y2 || flags!=flags2){

                        makeLine(xstart, ystart, x, y);
                        x2=x; y2=y;
                        wait(10);
                        }


        }
wasLeftPressed = false;
roiManager("Add");
print("second line");
i=i+1;
}
}
}
--
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: Coloring nodes according to their tags in TraKEM2

L'assegnista
In reply to this post by L'assegnista
Dear List,
A friend helped me with a python script to colorize nodes based on their
tags, I know is very simple script but I'm sure it could help other non
coding persons.
To set the color of untagged nodes simply change the color of the entire
treeline, this will not overwrite the colors assigned by the script.

import sys
from ini.trakem2.display import Display
from java.awt import Color


# Obtain the currently selected Tree in the canvas:
tree = Display.getFront().getActive()

root = tree.getRoot()
if root is None:
    sys.exit()

for nd in tree.getRoot().getSubtreeNodes():
    tags = nd.getTags()
    #print "tags ", tags

    if tags is None:
        continue

    for tag in tags:
        #print "tag",tag,type(tag), tag.toString()
        #Modify with your own tags and colors

        if tag.toString() == 'TAG1':
            nd.setColor(Color.yellow)

        if tag.toString() == 'TAG2':
            nd.setColor(Color.green)

        if tag.toString() == 'TAG3':
            nd.setColor(Color.red)

2016-02-16 15:54 GMT+01:00 Federico Luzzati <[hidden email]>:

> Dear list,
> Thank you for the very useful comments to my previous question! I'm here
> with another one..
> always on TraKEM2.
>
> I'm tracing fibers bundles with treelines and using tags to annotate each
> node based on the staining in another channel. To visualize the
> distribution of tags in 3D I tried the function "color path between two
> nodes tagged as" but I obtained strange results.
> Does anyone can suggest a method (or a script) to color nodes according to
> their tags?
>
> Thank you
>
> P.S. For Stephan, I don't know if I love the risky life, I just found that
> manual tracing is a very inspiring way of losing time!
>
>
> --
> Federico Luzzati, PhD
> Assistant Professor
> University of Turin,
> Dept. LIfe Sciences and Systems Biology (DBIOS)
> Via Accademia Albertina, 13 - 10123 Torino - IT
>
> Researcher at
> Neuroscience Institute Cavalieri Ottolenghi (NICO)
> Regione Gonzole, 10 - 10043 Orbassano (To) - IT
>
> tel. +39-0116704683/ -6631
> http://www.nico.ottolenghi.unito.it/index.php/it/adult-neurogenesis
>
> Sostieni con il tuo 5xmille il NICO e la ricerca sulle malattie
> neurodegenerative
> Firma nel riquadro "Finanziamento della ricerca scientifica e
> dell'Università"
> CF 97564560015
>
>


--
Federico Luzzati, PhD
Assistant Professor
University of Turin,
Dept. LIfe Sciences and Systems Biology (DBIOS)
Via Accademia Albertina, 13 - 10123 Torino - IT

Researcher at
Neuroscience Institute Cavalieri Ottolenghi (NICO)
Regione Gonzole, 10 - 10043 Orbassano (To) - IT

tel. +39-0116704683/ -6631
http://www.nico.ottolenghi.unito.it/index.php/it/adult-neurogenesis

Sostieni con il tuo 5xmille il NICO e la ricerca sulle malattie
neurodegenerative
Firma nel riquadro "Finanziamento della ricerca scientifica e
dell'Università"
CF 97564560015

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