Sample image and/or code
image1
image2
image3
getSelectionCoordinates(x, y); //returns array of x and y coordinates for selection (in this case a straight line has only two points and four coords)
ylength = y[0] - y[1]; //finds the length of the line in the y axis by taking the first y coordinate from the second
xlength = x[0] - x[1]; //finds the length in the x axis the same way
n = 4 //tell the program you will break the line into 4 segments
yinc = (ylength/n); //the increment in the y axis between each point's y coordinate
xinc = (xlength/n); //the increment in the x axis between each point's x coordinate
for (j=0; j<=n; j++) { //a for loop to plot points, repeats for the total number of segments + 1 (as 0 is counted)
xcoord = x[0] - (xinc*j); //calculates the x coordinate of the point to be plotted by subtracting the increment value (multiplied by the current segment number defined by 'j') from the first x coord of the line
ycoord = y[0] - (yinc*j); //calculates the y coordinate as above from the top-most point on the line
setKeyDown("shift"); //required to plot multiple points on the same selection (otherwise will only plot one point and overwrite them every time it loops)
makePoint(xcoord, ycoord); //makes a point selection at the x and y coords calculated above
}
Background
I am working with images of seed pods. and counting the number of seeds in each pod.
Analysis goals
I need to visually divide the seed pod into four segments of equal length so that I can count the number of seeds in each quarter of the pod.
The program works well for this when using the straight line tool. I simply use the straight line tool to draw a line along the length of the pod, then run the above program (Image1). It creates 5 dots equally spaced thus allowing me to count the number of seeds between each dot (Image2).
However, some seed pods are curved rather than straight (Image3). This makes the straight line tool ineffective for dividing the seed pod into equal segments. What I would like to do is alter the program such that it can be used on segmented lines, not just on straight lines. That way I can draw a segmented line such as the one shown in Image3 and have the program create dots to divide the segmented line into four equal segments.
Challenges
I can’t figure out how to get this to work for a segmented line. Conceptiually I think i’d have to first sum up the total length of all line segments, divide that by 4, figure out which line segment each of those points are in, and then get the program to make a point there? I’m not really sure how to do that though. Any help would be benificial. I am still new to coding.
I got the code originally from this post, and modified it slightly: