Intersection of a spline fitted curve and a straight line

Is there any way for me to find the intersection XY-coordinates of a spline fitted curve and a straight line? For example, in this sample image, how do I find the intersection coordinates of the blue line and the yellow curve?
Thanks in advance!

How about creating binary images of each line, and compute the intersection of those two binary images? White pixel would be the intersection and getting that coordinate is straightforward.

3 Likes

Dear @Kota and @Alice_Zhang ,
I was trying to do the same too, but it seems to me that a line cannot be converted easily to a mask with “Selection->Create Mask” it gives the warning “Area Selection required”.
An approach could be “Draw” those lines in Red,Green or Blue and then use the Colour Threshold.

Hoping to have been helpful,
good day
Emanuele

1 Like

No need to create a mask from the selection. Create blank images, draw the line and then “Draw” them in the foreground colour.
One potential problem is that 2 digital lines might intersect without sharing any pixels at all.
You could dilate your lines with a small kernel (e.g. Filter Maximum with radius 0.5) so you are sure that the two lines now intersect. Find the common pixels with AND of both images, and then find the centre of mass of the intersection with the particle analyzer.

3 Likes

hi @Kota, thanking for replying me. I have problems on creating binary images of each line. I use “Image->Overlay->Add Selection” to draw the lines, and then “Image->Adjust->Threshold” to set both upper and lower Threshold level to 250.(so that everything else is white except for the lines). I made binary of both images. Finally, when I use image calculator to AND both images, nothing happens. I figured this is probably because I did not create binary images properly. But I am not sure exactly where went wrong. Any hint would be helpful. Thank you!

Hi @Alice_Zhang ,

First of all, follwoing procedure matters with the color setting so please

  1. [Edit > Options > Colors…] and set Foreground:white and Background:Black.
  2. [Process > Binary > Options…] and tick “Black background”

These are my usual settings, and default probably is inverse but I explain with my setting.

Instead of thresholding, you can create a flat black image by

[Image > Selection > Select All] then [Edit > Clear]

Then duplicate the image by

[Image > Duplicate]

Now you have the 2nd black image.

Then place the first ROI in the first black image, (you probably have ROIs in the ROI manager, right?). Then

[Edit > Draw]

Will draw a white line in the first image. As @gabriel sensei accurately pointed out, we need to make the line one pixel thicker not to miss the crossing so

[Process > Binary > Dilate]

The first image is done. Then do the similar with spline-fitted line ROI and the second black image.

Now, select [ Image > Image Calculator …] and choose the first black image as image1 and the second as image2. Operation should be AND, and better to tick"create new image" so that you could test around.

To get the coordinate, [Analyze > Analyze Particles…] probably is the easiest.

just now have another idea:

for each line selection, convert to area by

[Edit > Selection > Line to Area]

and add the converted ROIs in the ROI manager. Then in ROI manager, select two Area ROIs just now added (highlight both) and click the ROI manager button “More >>” and select AND. This will end up in a small ROI at the intersection of original lines. To get coordinates of this intersection.

[Edit > Selection > Properties]

Then in the properties window, tick “list coordinates” and a list of coordinates appears. Average each x and y column and you get the final single intersection coordinate.

It should be more precise if you get all point coordinates for each line and get the intersection analytically, but this needs to be done from a macro/script.

2 Likes

Hi,

just in case anyone finds this I’ve suggest a solution here that takes the analytic approach suggested by @kota above.

Chris