Hello community!

I am trying to develop a macro, where I draw a line across an image, locate the points of the line which have the maximum intensities and measure the distance between these points.

This is as far as I managed to come, but I figured that the command “Array.findMaxima();” sorts the points according to ascending intensity and not to the x- or y-position of the line drawn:

intProf = getProfile();

maxValues = Array.findMaxima(intProf, 3600);

getSelectionCoordinates(xpoints, ypoints);

xmaxValues = newArray(maxValues.length);

ymaxValues = newArray(maxValues.length);

dxmaxValues = newArray(maxValues.length - 1);

dymaxValues = newArray(maxValues.length - 1);

distance = newArray(maxValues.length - 1);

for (i = 0; i < maxValues.length; i++){

xmaxValues[i] = xpoints[maxValues[i]];

ymaxValues[i] = ypoints[maxValues[i]];

}

for (i = 0; i < maxValues.length - 1; i++) {

dxmaxValues[i] = xmaxValues[i + 1] - xmaxValues[i];

dymaxValues[i] = ymaxValues[i + 1] - ymaxValues[i];

distance[i] = pow((pow(dxmaxValues[i], 2) + pow(dymaxValues[i], 2)), 0.5);

}

makeSelection(“point”,xmaxValues,ymaxValues);

Array.show(Distance);

I would be very glad to know, if there is a way to sort the maximum points to their x-position, in order for the distance calculation to work fine.

Thank you in advance!