Setting freehand lines without releasing mouse key

imagej

#1

Hey community,

is there a possibility to lock a freehand line just with pressing “t” without releasing the mouse key?

I have to measure the length of lots of lines with this tool and the ROI manager.
Two lines are always linked. So at the transition of this two lines I would just like to press “t” but not release the mouse key (or lift the pen - I will try it with a tablet next) at this area because I won’t find this exakt point again (and it is important to start with the measurement of the second line where the first line is terminated).

I hope you can help me! Thanks!


#2

No you cannot because if you press the mouse again on the end of the first line, then you select it, rather than start a new line.
But you can

  1. draw the line,
  2. release the mouse (do not move it),
  3. press t to store in the ROI manager,
  4. press ALT-SHIFT-A to remove the line you just draw and
  5. click again to start drawing the 2nd line.

#3

Isn’t it that you want to draw a segmented line and then treat each edge as if it were an individual line? Macro-wise it is relatively easy to pick up the coordinates of the vertices of the segmented line…


#4

I guess that is because it is trickier to get the lengths of the segments interactively.


#5

Stealing from this posting, I right-clicked the line tool making it segmented, then clicked once on the first bridge post, then the hand rail, then double-clicked the last post, then ran an adapted version of the length function, resulting in the Results window showing

58.0086, 325.1861

This is the recording:

run("Bridge (174K)");
///setTool("polyline");
makeLine(46,200,45,142,370,131);
l=selectionLength();
print(l);
function selectionLength() { 
lineLengthString="";
	getSelectionCoordinates(x, y); 
	segments = newArray(x.length-1); 
	lineLength =0; 
	for (i=1; i<x.length; i++) { 
		segments[i-1] =  sqrt( pow( (x[i-1] - x[i]),2) + pow( (y[i-1] - y[i]),2) ); 
		if(i>1){lineLengthString = lineLengthString + ", ";}
		lineLengthString = lineLengthString +segments[i-1]; 
      } 
     return lineLengthString; 
}

#6

Thank you for your efforts and answers!

I think I have to go more in detail to understand my problem…

Here is a short video, it’s not good but you can see what I am doing:

I need to get the length of the cress seedlings visible in this picture. I have 100-200 hundrets of such pictures a week, all of them show 16 seedlings.
So I need a quick tool to measure. The best solution was with imageJ, drawing the line along the seedling with the freehand tool and combine it with the ROI Manager. In future I will use it with a tablet and special pen so I can follow the seedlings curve much better, but won’t be really able to catch the same point twice (end of shoot/start of root). It’s just a test of the software now with the mouse and normal PC.

The length of shoot and root is needed separately - but if I have to click to end the line and start with a new line I can’t catch the same point and that would be important. Making it segmented etc. is too time-consuming.

I hoped that there would be a way to set in the line without releasing the mouse/ in future lift the pen (which is more difficult to catch the point again because the mouse still is at the same point after releasing it - but the pen is moved), for example just to press t…


#7

Apart from that you maybe can segment each sprout automatically (post an image and see what is possible?), I think if you first draw the freehand line, then have a macro that adds it to the roi manager as an interpolated line with interval 1 (which makes it a series of points), then for all lines in the image you select which point divides the sprout in the shoot and root, then the macro measures all lengths, you end up with what you want?


#8

Thank you! That sounds good and might be another option. Unfortunately I am not that familiar with ImageJ yet: do I have to write the macro by myself or is there one I can use?

I already tested round about 40 possible software solutions for an automatic analysis of the seedlings but none (even not IJ_Rhizo oder WINrhizo) was convincing and successful for various reasons…


#9

Good day,

please post at least one typical raw image in the original TIF- or PNG-format. No JPG-format though, because JPG introduces artifacts! You may also post images as Zip-archives.
(Converting a JPG-compressed image to TIFF- or PNG-format doesn’t make sense.)

How do you acquire the images?
(Illumination, Camera, Distance, Reproducibility, etc.)

Please keep in mind that the quality of the original images is of utmost importance. Optimum image acquisition is better than any post hoc image processing.

Regards

Herbie


#10

Hey Herbie :slight_smile:
Thank you! So far we just scanned the bags with the cress with a Canon scanner.
I only get JPG then. We try to find a solution with a cam and incident light as an alternative to get photos with a better quality and depth of focus now.
I work with this system only recently and I try to improve every step so it still is in progress. But unfortunately I can only show you an example like this at the moment.

(How can I upload something? I think the upload of my picture wasn’t successful; I used the upload button above the text box…)


#11

So far we just scanned the bags with the cress with a Canon scanner.

You put the specimen with the soil etc. onto a document scanner?

I only get JPG then.

Cannon scanners can deliver a lot of formats, e.g. PNG and TIFF. We prefer the latter.

How can I upload something?

Maybe as a new user of this forum there are certain restrictions (I’m unable to change them). You may perhaps use a dropbox-like way of posting …

HTH

Herbie


#12

I used a free host now to upload the picture: https://ibb.co/hrRDJp
As you can see we don’t use soil, just a little bit water and chromatography paper :slight_smile:

For scanning we can choos JPEG in color and b/w and as an alternative TIFF, but only in b/w. And I definitely need the color to distinguish between root and shoot.


#13

Thanks for the image!

The image is not that bad but there is a strong shine through due to the wet chromatography paper.
You really should use a homogeneous dark background.
Furthermore, please avoid any overlapping of the specimens!

Now please tell us what parts you are interested in by drawing onto this image.
Please specify exactly what you need to be automatically detected or measured. Please be aware of the fact that in the end we need a formal (mathematical) definition because this is what computers understand.

Regards

Herbie

PS:
Closer inspection of the sample image shows that the wet specimens are enclosed in a plastic bag which leads to disturbing structures in the image. Image acqusiition should be revised and better contrast between the stalks and the background should be reached.


#14

Provided you don’t mind drawing the lines manually but just need a tool that chains several freehand segments after each other (and adds each of the segments to the ROI Manager), you can write a custom tool macro to aid in your task.

Here’s an example Segmented Freehand Line Tool that adds the current freeline selection to the ROI manager whenever you press or release ⇧Shift, and starts a new freeline selection at the last mouse position. (When you release the mouse button, it adds the last selection to the manager and the ⇧Shift state is ignored.)

// Author: Jan Eglinger

macro "Segmented Freehand Line Tool - C008P00345878798aff0-Cf44D00D01D10D11D58D59D68D69DeeDefDfeDff" {
    var leftButton = 16;
    var shift = 1;
    var shiftChanged = 0;
    getCursorLoc(x, y, z, flags);
    xArr = newArray(1); xArr[0] = x;
    yArr = newArray(1); yArr[0] = y;

    // drag mode
    while (true) {
        getCursorLoc(x, y, z, flags);
        if (flags&leftButton==0) {
            // button released - add last selection
            roiManager("Add");
            return;
        }
        xArr = Array.concat(xArr,x);
        yArr = Array.concat(yArr,y);
        makeSelection("freeline", xArr, yArr);
        if (flags&shift!=shiftChanged) {
            // shift key changed - add selection
            roiManager("Add");
            xArr = newArray(1); xArr[0] = x;
            yArr = newArray(1); yArr[0] = y;
            shiftChanged = flags&shift;
        }
        wait(10);
    }
}

To install the macro tool, paste the code into a Plugins > New > Text Window… and choose Macros > Install Macros Ctrl-I.

Here’s what you can get:

image

You should then be able to measure all ROIs simply by clicking Measure on the ROI Manager window.