I'm working on image processing and I need to know the angle between the center of the image (320, 320) to the several objects e.g. ([22.5, 114], [350, 500]). The image size is 640X640.
When I'm calculating north on the image [0,320] the angle with the following method is 45º, and it should be 0º.
center = [im.size[0]/2, im.size[1]/2]
vector_1= [center[0], center[1]]
vector_2 = [0, 320]
unit_vector_2 = vector_1 / np.linalg.norm(vector_1)
unit_vector_1 = vector_2 / np.linalg.norm(vector_2)
dot_product = np.dot(unit_vector_1, unit_vector_2)
angle = np.arccos(dot_product)
mydegrees = math.degrees(angle)
But when I calculate the angle with:
myradians = math.atan2(vector_1[1]-vector_2[1], vector_1[0]-vector_2[0])
mydegrees = math.degrees(myradians)
The angle is 0, but doesn't work with other coordinates such as [5, 320]
I need to calculate angles from 0º to 360º in the whole image, taking into account the dimension of the image and the location of the objects in it, always assuming that the center of the image will be the origin coordinate.
The next image is an example:
The blue dot represents the center [320,320], and the red dots are the pixel coordinates that I'm looking for the angle, assume the north is the 0º [0, 320] and east is 90º [320, 0], south 180º [0, -320], west [-320, 0].
The dots coordinates are:
(x=[22, 74, 88, 478.0, 635.0, 350], y=[114, 154, 540.0, 529.0, 217.0, 500])
How do I solve this problem? Thanks!
