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

asked 2015-09-04 02:59:23 -0600

zms gravatar image

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

image description

edit retag flag offensive 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

Comments

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 gravatar imageLBerger ( 2015-09-04 03:27:53 -0600 )edit

@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.

zms gravatar imagezms ( 2015-09-04 03:49:15 -0600 )edit

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

LBerger gravatar imageLBerger ( 2015-09-04 03:56:26 -0600 )edit

@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

zms gravatar imagezms ( 2015-09-04 04:02:37 -0600 )edit

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

LBerger gravatar imageLBerger ( 2015-09-04 04:28:20 -0600 )edit