Herbie and 7rebor thank you.

### My ‘issue 2’

Concerning the second issue: It isn’t an issue!

I’m not sure what it was I said that implied I wanted the line to move (nor does it matter). In any case commenting(/removing) `makeLine( x[0], y[0], x[1], y[1] );`

has (as your suggested resolved the ‘*problem*’.

### New lines

I still don’t fully understand why the “/n” delimiter doesn’t work as expected - something to do with Notepad?

I’m not sure whether it is exclusively a Windows Notepad issue as the `TXT`

files were not being read correctly when imported into `R`

. Needless to say though your suggested fix worked a charm. For the record, and to help any others, I replaced the following four lines from Herbie’s second code block with the six from 7rebor.

`txtData = "" + round(x[0]) + "\t" + round(y[0]) + "\n" + round(x[1]) + "\t" + round(y[1]); File.saveString( txtData, path ); //print( "1. Intersection:\tx = " + round(x[0]) + ";\ty = " + round(y[0]) + ";" ); //print( "2. Intersection:\tx = " + round(x[1]) + ";\ty = " + round(y[1]) + ";" );`

### Plot line

smith_roberj, I was aware of the plot line tool and that it could be used to manually identify the binary transition. What I was after was an automated method that only required the line to be drawn. Herbie’s macro with the `/n`

fix by 7rebor does this.

### In summary

Thank you for your help. The macro now does exactly what I needed it to do. What a great community.

#### Final thought

respected the correct way of drawing the line selection?

I was just wondering if someone could explain to me why the direction the line is drawn matters? Does it determine the order the landmarks are returned?

The reason I ask is that it just so happens to be (and there’s no way anyone could know this) but the direction of left-to-right and top-to-bottom to be the counter-intuitive for me personally (I tend to draw from the other end, i.e. from the first landmark to the second). Certainly something I can live with / get used to, but was curious about the reason and whether it could be changed.

## Here’s the final macro

```
// START
path = getDirectory("image") + File.nameWithoutExtension + ".txt";
if ( selectionType() < 0 ) exit( "Line selection required!" );
getSelectionCoordinates( x, y );
slp = slope( x[0], y[0], x[1], y[1] );
len = lengt( x[0], y[0], x[1], y[1] );
profile = getProfile();
extrema( profile );
profile = Array.findMaxima( profile, 0, 1 );
profile[1] = len - profile[1];
if ( profile.length > 2 ) exit( "Image must be binary!" );
intersection( x, y, slp, profile );
file = File.open(path);
txtData1 = "" + round(x[0]) + "\t" + round(y[0]);
txtData2 = "" + round(x[1]) + "\t" + round(y[1]);
print(file, txtData1);
print(file, txtData2);
File.close(file);
exit();
//-----------------------------------------------------
function slope( x_0, y_0, x_1, y_1 ) {
return -( y_0 - y_1 ) / ( x_0 - x_1 );
}
function lengt( x_0, y_0, x_1, y_1 ) {
return sqrt( pow( x_0 - x_1, 2 ) + pow( y_0 - y_1, 2 ) );
}
function extrema( p ) {
for ( i = 1; i < profile.length; i++ ) {
p[i-1] = abs( p[i] - p[i-1] );
}
}
function intersection( xx, yy, s, p ) {
for ( i = 0; i < 2; i++ ) {
if ( i > 0 ) { sign = -1; } else { sign = 1; }
dx = sign * sqrt( pow( p[i], 2 ) / ( 1 + pow( s, 2 ) ) );
xx[i] += dx;
if ( slp != 1/0 ) { yy[i] -= s * dx; } else { yy[i] += sign * p[i]; }
}
}
// END
```