Drawing vertical lines inside a polygon selection [ImageJ]

imagej2

#1

Hello

I am looking for a way to draw vertical lines in a selected area. I found a older post that used a macro which drew lines in a rectangle selected by the user. I was hoping someone can provide me with the code to do it with a Polygon selection. If that isn’t possible, is there a way to use a macro to draw lines in between two manually drawn horizontal lines. The drawn lines won’t always be perfectly straight though.

Thanks in advance
Julius


#2

Good day Julius,

I must admit that I have no idea what you like to perform. Please make a rough sketch of what you like to obtain and please be very specific concerning what is what:

Lines can be drawn as selections or as overlays or directly to an image. We need to know how you like to draw and what you like to draw.

Furthermore, it would be interesting to know for what pupose you want to do the drawing, because quite often a goal is much easier to reach by completely different approaches.

Regards

Herbie


#3

Thanks for the reply

Basically what I want to do is draw two lines on an image (the two black lines) and have imagej generate 90 degree lines between the two lines I drew (the white lines).

The spacing should be about every 10 pixels or so. I want to then measure each line generated by imagej.

I am not too sure if it would be easier to draw two lines and measure between them or use the polygon tool to create a “box” for imagej to draw the lines in.


#4

You didn’t answer how you like to draw.

and have imagej generate 90 degree lines between the two lines I drew

In your drawing the black lines aren’t parallel, so 90 degrees will work for only one of them.

The spacing should be about every 10 pixels or so

“every” ??

I want to then measure each line generated by imagej.

What does that mean?
Measure what?

Please be more specific

Herbie


#5

It should be an overlay. I am looking for the distance of each line (the amount of pixels).

I know the lines aren’t parallel but they almost always never will be.

I am currently doing it all by hand. I draw the two horizontal lines. Then I draw a vertical line between the two. Than I move ten pixels or so to the right and draw another vertical line and make it shorter or longer depending on the horizontal lines.


#6

If they are not parallel you cannot have 90 degrees lines between them.
And if you’ve two parallel lines all the 90 degrees lines you will generate (with 1,3,10,… whatever value of spacing between them) they will all measure the same.


#7

I know the lines aren’t parallel but they almost always never will be.

How do you expect a machine to cope with this?

I am looking for the distance of each line (the amount of pixels).

The distance is 10 pixels — no?

Clueless,

Herbie


#8

ok now maybe I’ve got what you want to do:
find with a spacing of 10 pixels the minimum distance between the 2 black lines?


#9

My trigonometry is no good. Can you explain why I can’t have a 90 degree line between the two vertical lines?

I am looking for the distance of the vertical lines between the two horizontal ones.

I guess I was thinking that if I can get the x,y-coordinates of the horizontal lines at each pixel I can draw vertical lines between the two horizontal lines.


#10

Yes. that would be correct


#11

I am looking for the distance of the vertical lines between the two horizontal ones.

OK, but you will get two values if the black lines aren’t parallel.

vertical lines between the two horizontal lines

Please note that in your case “(absolute) vertical” and “90 degrees with respect to the black lines” is not the same!

Herbie


#12

Sorry. I am a little dumb like that


#13

I know that will be the case yes. But just to make sure I understand you. If there are only twenty pixels, I will get two values, but if there are 50 pixels I will get 5 values?


#14

Here is an exaggerated drawing of absolute vertical lines between non-parallel black lines:
sketch-1

Evidently the red lines have different lengths, i.e. you get two values for the distance.

Here is an exaggerated drawing of lines that are 90 degrees to the top black line:
sketch-2

Again you get two values for the distance.

If you compare both examples, you may notice that both distances in the second image are longer than their counterparts in the first image.

So what we need to know is, whether you are happy with two absolute vertical lines between the black lines and if you want the average of both distances or not.

I hope this was clear enough.

Herbie


#15

It would be your first example then. So absolute vertical lines which I then calculate the average of. But I need the value of each individual line (the macro shouldn’t just give me the average).


#16

Understood, and now please tell us how the encircled point (or one of the other three intersection points) is defined?
The x-position of one of the vertical red lines would do as well. How is it defined?

sketch-3

Herbie


#17

Well normally I would just work from one side of the line to the other. But I don’t know if it is possible to program that because the horizontal lines changes position the whole time.

Unless we get the angle of the horizontal line, use the start and end point and generate coordinates via that. Which sounds way more complicated than it is worth.


#18

from one side of the line to the other

You mean the end points of the black line?
Will this line then be 10pixels in x-direction?

I still have problems to understand what you need.

Herbie


#19

Yes the end points of the black line.
The line covers x amount of pixels.


#20

Yes the end points of the black line.

Does this imply that both black lines have the same length in x-direction and start at the same x-position?

If not which of both lines defines the spacing of the vertical lines?

Herbie