Automatically forming parallel lines to below manually-drawn line?


I am working with chromosomes and am analysing fluorescence of 3 stained areas (two above, one below). I have a macro already, that would read fluorescent peaks of 2 top points through which a short, straight line the user would draw. I now want to add parallel lines that will automatically form below it so fluorescence of the single point below it can be measured too (automatically, so users don’t have to draw them too, and so the peaks can be compared in the same macro).

I do have ideas, like using the Pythagorean Theorem; or drawing a perpendicular line, and then stacking a bunch of perpendicular lines to that perpendicular line to below it; or repeating the original line again and again; or stacking rectangles on top of each other under the original line; or simply adding parallel lines to below it. I was also thinking that I could add the command to each individual line, or add it so it works on the ROI Manager. I have no idea, however, how to do any of this.

I am using Fiji (ImageJ) and Python 3.

How would I go about doing this?

Thank you very much!!!

I am a bit confused about what you mean when you say things like “above” and “below”. Could you try to clarify?


You can check out this older forum thread … perhaps you can modify the code posted there:


Hi @vew,

Maybe a sketch of the desired result or a sample image could help us to understand the goal you want to achieve.

Please clarify what you mean with ‘top points’. Are they coordinate pairs in the x-y plane (where the origin (0,0) is top left) located around the lesser y values or is their intensity amongh the highest in the x-y plane? Likewise please explain for ‘below’; is it about the higher y values in (x,y) coordinate pairs or the lower intensity values? Or do you have 3D data, or is your data in 3 stack slices? What determines the choice of [location, value] of the ‘single point below’?

Hi @Andrew_Shum and @eljonco,

Thanks so much for replying!! I’ve uploaded an image of the desired results, sorry for not doing so sooner!
They’re on z stack, so they should be on the same plane. The x-y plane is coded to accommodate the manually drawn line the users will draw. I would like the lines to be formed above and below along the x-axis.

Thank you so much for your attempts already :slight_smile:

Thanks very much!!

Thanks for the thread @etadobson!

1 Like

I think maybe you can take some ideas from this thread:

here there are some code (and links to other similar examples) to draw perpendicular and parallel lines, I hope that help



Thanks @emartini for the thread! I did find that a few days ago through Google, but the code doesn’t seem to work? I’d run it on Fiji and it keeps coming back with errors unfortunately!

Good day,

would you be so kind and tell us the spacing of the lines?



could please write a little example where the code gives you errors?
and also the errors traceback?

Here is an ImageJ-macro that does what you’ve described:

h = getHeight();
d = h / 20;
getSelectionBounds(x, y, w, height);
run("Select None");
setColor(0, 0, 0);
pos = y;
do {
   Overlay.drawLine( x, pos, x+w, pos );
   pos += d;
} while ( pos < h );
pos = y - d;
while ( pos >= 0 ) {
   Overlay.drawLine( x, pos, x+w, pos );
   pos -= d;

Paste the above macro code to an empty macro window (Plugins >> New >> Macro).
The initial (hand-set) line must be a line selection.
After the line selection is drawn you are to run the macro.

You may set the line-spacing d to a value of your liking.
The same holds for the color of the lines (presently black).

The lines are drawn as an overlay that can be hidden and shown and can be made permanent by flattening.




Thanks very much Herbie!!! The lines do come up, thanks so much!

How would you go about making it arrange themselves according to the line manually drawn? It’s currently automatically forming parallel lines, but across the actual Fiji window.

I can’t confirm what you report.

The lines are as long as the initially drawn line selection.

Perhaps I don’t understand what you like to see…



The code unfortunately gives me lines that runs across the whole window (automatic lines in red (206,17, 38)). I did copy the code as you’ve written?

Thank you so much for your help I do appreciate your time!!

Sorry but you wrote:

I would like the lines to be formed above and below along the x-axis.

You’ve not mentioned that the initially drawn line selection may be oblique.

Good luck


Is there anything I can add to the code to accommodate oblique lines?

Thanks again I really appreciate your help!

Now you’ve moved the goal posts. It looks like you need to visit the translate command as suggested by @etadobson

@yempski I’m really sorry I didn’t realise I had to say it was oblique, I thought parallel would have been sufficient. I have no background whatsoever in coding, I am just helping out a good friend however I can. Sorry again. Thanks everyone for your time :slight_smile:

[…] I thought parallel would have been sufficient. I have no background whatsoever in coding, […]

Sorry, but this has nothing to do with coding but with basic geometry, i.e. at best with highschool mathematics.

BTW, why doesn’t your good friend post here on the Forum?



Yeah, I meant, I thought ‘parallel’ means lines in a plane that don’t meet, regardless of slant.

I don’t know why she’s not thinking of posting here, she’s doing a Masters and not very good at technology, and neither am I, but I thought I could surprise her with a solution, she’d be ecstatic.

Sorry if you are offended, it was not my intention at all, I apologise.