There’s a macro function (Array.findMaxima) to get the maxima from an array, within a tolerance (there’s also one for the minima). You can combine it with getProfile to extract the profile maxima, then use the ends of the profile line to map those coordinates back to the image, like in this example:

Hi Mafalda,
concerning your first question, a list of maxima of an image (not a plot), you can use “Find Maxima” and select “List” as “Output type”. Then you get a Results table with the x&y coordinates of the maxima. Use the Command Recorder (Plugins>Macros>Record) to see what the macro command looks like.
You can retrieve the table values with the macro command Table.get(columnName, rowIndex).
– Michael

I’m a little confused regarding the goal of your macro. Could you give us some example of the type of analysis you are trying to achieve?

The second line of your macro (run("Area to Line")), gets an area Roi and makes a snip in its perimeter, effectively turning it into a line Roi. Is this what your are looking for? If you use this on a thresholded area in the image you provided (a fiber?), you would end up with an intensity measurement along the perimeter, not along its axis. Also, you would have two readings of the same section (one on each side). In fact, as you are not using the “exclude peaks on edges of plot” option in the BAR plugin, if you have a “high spot” in the place where the command splits the perimeter, you would get two adjacent points selected (as the perimeter wraps up in the same spot).

That’s not really true since I’m only having two closed detections in some spots:

In fact, that’s actually the case. If you look closely, the profile you showed is almost a mirrored image. You are counting the crossings twice, gowing from one end of the ROI to the other, and once again on the way back.

You can also check the following: the total length of the profile (about 60000 units) should be twice its expected length.

The roi line shown in the images is in fact double, a few pixels apart. Do you use the Make band command at some point? I can’t find a simple built in solution to get this kind of thin areas into a single line. I know @superresolusian was working on something similiar a while back . Also, this post form @iarganda might provide a useful solution, by first skeletonizing the area and then getting the longest line.