Login  Register

Re: measuring two lines perpendicularly

Posted by Romain Penz on Feb 08, 2016; 9:10am
URL: http://imagej.273.s1.nabble.com/measuring-two-lines-perpendicularly-tp5015503p5015570.html

I have made some progress, modifying the L-Shape Tool macro from Jerome Mutterer.

Now I'm able to get two separate lines (2 separate Roi) perpendicular. See the code below.

To get exactly what I need, I have to found a solution in order to :

- Be able to "click" with the left mouse to define the beginning of the second line (which is automatic in the code below)

- then drag the line to the desired length (following a linear function perpendicular to the first one). Is there a function to do this? I've searched but with no results.

Do you know how to do this?



 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);
       }
roiManager("Add");
       if (x!=xstart || y!=ystart) {
          drawLshape(xstart, ystart, x, y);
roiManager("Add")

    }
 }

 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); // l-shape
          //makeLine( x1,y1,x2,y2,x2 + wsa,y2 + wca,x2 - wsa,y2 - wca); // t-shap
 

                 


//makeLine( x2+wsa,y2+wca,x2-wsa,y2-wca); t-shape 2 separate lines
//makeLine( (x1+x2)/2+wsa,(y1+y2)/2+wca,(x1+x2)/2-wsa,(y1+y2)/2-wca); //x-shape 2 separate lines
makeLine( x+wsa,y+wca,x-wsa,y-wca); // X-L-or-T-shape 2 separate lines


          x3=x;y3=y;
          wait(10);
       }
    }
 }

________________________________________
De : ImageJ Interest Group <[hidden email]> de la part de Gabriel Landini <[hidden email]>
Envoyé : mardi 2 février 2016 16:38
À : [hidden email]
Objet : Re: measuring two lines perpendicularly

On Tuesday 02 Feb 2016 14:59:59 you wrote:
> I will try that plugin. It could be an effective solution for some spores
> associated with a rectangular ROI (elliptic spores especially). Thanks a
> lot.

Rather than doing it by hand, you could also try to binarise the spores, then
extract the feret diameter and the breadth (which is the maximum distances
from the feret to the boundaries, measured perpendicularly to the feret. Note
thought, that the segments on each side of the feret are not necessarily co-
linear. The Particles8 plugin can compute that.  Or compute the size of the
bounding box based in the rotating calipers algorithm. I think BoneJ can do
this.

Cheers

Gabriel

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

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