Constructing line perpendicular to other line (saved in ROI manager)

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

Constructing line perpendicular to other line (saved in ROI manager)

rafesgre
Hi everyone.
 
does someone know how to create (automatically) a line that is perpendicular to a previously created straight line (saved in the ROI manager) in ImageJ/Fiji? Of course, you can do it manually, but that will never be a exactly perpendicular line.
I'm sure that there already exists a simple solution, but I just cannot find it.
 
Best wishes,
JK

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

Re: Constructing line perpendicular to other line (saved in ROI manager)

Rasband, Wayne (NIH/NIMH) [E]
> On Mar 13, 2015, at 6:36 PM, Mqoi Mgfsu <[hidden email]> wrote:
>
> Hi everyone.
>
> does someone know how to create (automatically) a line that is perpendicular to a previously created straight line (saved in the ROI manager) in ImageJ/Fiji? Of course, you can do it manually, but that will never be a exactly perpendicular line.
> I'm sure that there already exists a simple solution, but I just cannot find it.

The following macro creates a line perpendicular to a previously created line in the ROI Manager.

-wayne

  count = roiManager("count");
  if (count==0)
     exit("ROI Manager line selection required");
  roiManager("select", count-1);
  if (selectionType!=5)
     exit("Straight line selection required");
  run("Rotate...", "angle=90");
  roiManager("Add");
  roiManager("Show All without labels");

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

Re: Constructing line perpendicular to other line (saved in ROI manager)

rafesgre
Hi wayne.

thank you very much for the macro!
Just two questions:
1) When I use the macro, it's only possible to draw a line that is perpendicular to the last line in the list of the ROI manager. Even if I select another line in the ROI manager, the new line will always be perpendicular to the last line in the ROI manager.
Is there a way to change this behaviour?
2) The newly created perpendicular line is always found at midlength of the "reference line" (= the previous line in the ROI manager). That is ok, because I can afterwards drag this line to the position where I would like to have it (however, I still have to modify it, because I also need a certain length). But is there also a possibility to draw the line that needs to be perpendicular (to the previous line) by starting from a point I choose and then attaching this line at 90° (i.e. perpendicular) to the previous line? So, to explain it another way:
  a) Start drawing the requested line from a a certain point
  b) Draw the line near to the previous line, to which it should be perpendicular
  c) The macro should now recognize that there's a "sticky" line to which our new line should be perpendicular to
  d) Complete the drawing of the line which should now be perpendicular to our "sticky" line and start from the point that we chose at a)

Is it possible, to do something like that?

Best wishes,
JK
Reply | Threaded
Open this post in threaded view
|

Re: Constructing line perpendicular to other line (saved in ROI manager)

Rasband, Wayne (NIH/NIMH) [E]
On Mar 14, 2015, at 12:41 PM, rafesgre <[hidden email]> wrote:

>
> Hi wayne.
>
> thank you very much for the macro!
> Just two questions:
> 1) When I use the macro, it's only possible to draw a line that is
> perpendicular to the last line in the list of the ROI manager. Even if I
> select another line in the ROI manager, the new line will always be
> perpendicular to the last line in the ROI manager.
> Is there a way to change this behaviour?
> 2) The newly created perpendicular line is always found at midlength of the
> "reference line" (= the previous line in the ROI manager). That is ok,
> because I can afterwards drag this line to the position where I would like
> to have it (however, I still have to modify it, because I also need a
> certain length). But is there also a possibility to draw the line that needs
> to be perpendicular (to the previous line) by starting from a point I choose
> and then attaching this line at 90° (i.e. perpendicular) to the previous
> line? So, to explain it another way:
>  a) Start drawing the requested line from a a certain point
>  b) Draw the line near to the previous line, to which it should be
> perpendicular
>  c) The macro should now recognize that there's a "sticky" line to which
> our new line should be perpendicular to
>  d) Complete the drawing of the line which should now be perpendicular to
> our "sticky" line and start from the point that we chose at a)
>
> Is it possible, to do something like that?

You can do this with a tool macro, similar to the attached L-Shape Tool macro by Jerome Mutterer, which I found by searching the mailing list archives. You may need to modify this macro to get it to work exactly the way you want. The macro is also available online at

    http://imagej.nih.gov/ij/macros/tools/L-ShapeTool.txt

// L-shape Tool
//
// This macro tool creates an L-shaped line selection.
// Click and drag the mouse to set the first segment.
// After the mouse button is released, drag to set the
// second segment and click to finish.
// Author: Jerome Mutterer

 macro "L-Shape Tool -C000L1991L91e6" {
    run("Line Width...", "line=1");
    getPixelSize(unit, pixelWidth, pixelHeight);
    getCursorLoc(x, y, z, flags);
    xstart = x; ystart = y;
    x2=x; y2=y;
    while (flags!=0) {
       getCursorLoc(x, y, z, flags);
       if (x!=x2 || y!=y2)
          makeLine(xstart, ystart, x, y);
          x2=x; y2=y;
          wait(10);
       }
       if (x!=xstart || y!=ystart) {
          drawLshape(xstart, ystart, x, y);
    }
 }

 function drawLshape(x1, y1, x2, y2) {
    a = atan ((x2-x1)/(y2-y1));
    x3=0;y3=0;
    while (flags&16==0) {
       getCursorLoc(x, y, z, flags);
       if (x!=x3 || y!=y3) {
       sign=1;
       if (x2>x) sign=-1;
          w=sqrt ((x2-x)*(x2-x)+(y2-y)*(y2-y));
          wsa = sign*w*sin((PI/2)+a);
          wca = sign*w*cos((PI/2)+a);
          makeLine( x1,y1,x2,y2,x2 + wsa,y2 + wca);
          x3=x;y3=y;
          wait(10);
       }
    }
 }


> --
> View this message in context: http://imagej.1557.x6.nabble.com/Constructing-line-perpendicular-to-other-line-saved-in-ROI-manager-tp5011962p5011965.html
> Sent from the ImageJ mailing list archive at Nabble.com.



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

Re: Constructing line perpendicular to other line (saved in ROI manager)

rafesgre
Hi wayne,

thank you again! This is very close to what I would like to do.
Unfortunately my macro skills in ImageJ approach zero ^^ (I've just started
using the program). Do you know how to modify the macro so that the
perpendicular line can be placed wherever I want it (along the other
line)? I don't necessarily want to create a L-shape, but a T-shape (or
something in between) is also fine (as long as the two lines are
perpendicular to each other).

Best wishes,
JK
Reply | Threaded
Open this post in threaded view
|

Re: Constructing line perpendicular to other line (saved in ROI manager)

Jerome Mutterer-3
Dear JK,
To draw a T-shaped line selection instead of the L-shaped selection, change
the third line from the end of the code to:

          makeLine( x1,y1,x2,y2,x2 + wsa,y2 + wca,x2 - wsa,y2 - wca);

Sincerely,

Jerome.




On 16 March 2015 at 10:54, rafesgre <[hidden email]> wrote:
>
> Hi wayne,
>
> thank you again! This is very close to what I would like to do.
> Unfortunately my macro skills in ImageJ approach zero ^^ (I've just
started

> using the program). Do you know how to modify the macro so that the
> perpendicular line can be placed wherever I want it (along the other
> line)? I don't necessarily want to create a L-shape, but a T-shape (or
> something in between) is also fine (as long as the two lines are
> perpendicular to each other).
>
> Best wishes,
> JK
>
>
>
> --
> View this message in context:
http://imagej.1557.x6.nabble.com/Constructing-line-perpendicular-to-other-line-saved-in-ROI-manager-tp5011962p5011981.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html




--
Jerome Mutterer
CNRS - Institut de biologie moléculaire des plantes
12, rue du Général Zimmer
67084 Strasbourg Cedex
www.ibmp.cnrs.fr

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

Re: Constructing line perpendicular to other line (saved in ROI manager)

rafesgre
Dear Jerome,

thank you for your help and apologies for the bad description that I made!
I would like to be able to choose where to place the "short part" of the "L" (or of the "T"). I've attached an image - hopefully, this clears, what I try to achieve.



There's one long line that I draw first. Afterwards I created two additional lines (but one would be already fine), that are perpendicular to the first line and are placed according to my preference (so, they are not just placed at one of the ends of the first line, i. e. no "L"- or "T"-shape is created).

Best wishes,
JK