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:,(x,y),3,(255,0,0),-1)
        if len(points) >= 2:
        cv2.imshow("image", img)
points = []

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


1 Like