# Automatically forming parallel lines to below manually-drawn line?

Tags: #<Tag:0x00007fa302816a30> #<Tag:0x00007fa3028168f0> #<Tag:0x00007fa302816710> #<Tag:0x00007fa3028165d0> #<Tag:0x00007fa302816418> #<Tag:0x00007fa3028161e8>

#1

Hi!

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!!!

#2

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

#3

@vew

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

eta

#4

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’?

#5

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.

Thanks very much!!

#6

#7

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

Emanuele

#8

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!

#9

Good day,

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

Regards

Herbie

#10

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

#11

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

``````h = getHeight();
d = h / 20;
getSelectionBounds(x, y, w, height);
run("Select None");
setLineWidth(1);
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;
}
Overlay.show;
exit();
``````

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.

HTH

Herbie

#12

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.

#13

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…

Regards

Herbie

#14

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!!

#15

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

Herbie

#16

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

Thanks again I really appreciate your help!

#17

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

#18

@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

#19

[…] 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?

Regards

Herbie

#20

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.