# How to draw straight line inside a thresholded image [closed]

Hello, I have 2 questions

1) If we calculate the Euclidian distance between two points from the open cv function, would it be able to know the gradient of the straight line?

2) If I have a centroid inside an image below, what would be the best method to draw a straight line inside the thresholded image from the point to the other? will the max and min coordinates of the straight line can be calculated?

thanks edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by sturkmen close date 2020-10-21 13:34:22.618533

first question (1) Why do you mean by gradient of the straight line? Is it relative to line equation (a.x+b.y+c=0) or gradient in image?

Second question you can use moment to have minor and major axis and may be you use boudingRect to draw a line. I don't think that there is universal answer (example fractal shape)

@LBerger, on the first question - it is related to the line equation. y = mx + c, where m is the gradient either it is - or + value. Sorry for the confusion. if let say that I have two points and I get the Euclidian distance, can I know whether the line is negative of positive m?

Ok, for second question, i'll try to get the options given.

so you can use line with parameter the two points used in your euclidean distance

@LBerger, yes the line would be able to draw between the points. So is it going to give the information either the gradient of line is + or -?

Sorry to ask this from the first answer, how can I use moment information to have the major and minor axis? I can get the moment information but not sure how I can put it for the axis.

Tq

Line equation is a.x+b.y +c =0. If you know two point p1 and p2 belonging to line then a=p2.x-p1.x and b=-(p2.y-p1.y) and you have line slope

For moment i think you can find some usefull information in this document