Measuring the distance between two drawed lines in python

I am trying to measure the mean, max, min, and SD distance between two lines, drawn by mouse in python. My main goal is to measure the retinal thickness of images obtained by medical devices (Look at the image attached please).
However, I don’t know how can I assign a value to both lines and then measure the parameters among them.


Raw Image
I only could write this code to draw a line using mouse:

import cv2
import numpy as np
def click_event(event,x,y,flags,param):
    if event == cv2.EVENT_LBUTTONDOWN:
        cv2.circle(img,(x,y),3,(255,0,0),-1)
        points.append((x,y))
        if len(points) >= 2:
            cv2.line(img,points[-1],points[-2],(0,255,0),1)
        cv2.imshow("image", img)
cv2.imshow("image",img)
points = []
cv2.setMouseCallback('image',click_event)
cv2.waitKey(0)

Thank you

pick a model for your lines. piecewise linear? spline? bezier? …?

the model should support “nearest point on the line” queries, or it should be able to give you a Y value, given an X value. if you picked “piecewise linear”, both of those things are easy to calculate.

now define each line from points.

then either

  • walk along the lines (increasing X values), get the Y values, and calculate vertical distance
  • walk along one line (arbitrarily, perhaps as a function of path length), and then query the other line for its nearest point, then consider that distance
1 Like

related:

1 Like