How To Get Value Of Pixels Which Are At A Certain Angle From Another Pixel?
I'm trying to implement a method where I have to obtain the values of all those pixels which forms a line at a certain angle through a pixel (i, j) Consider the following code snip
Solution 1:
You can use some trigonometry. Recall that sin(angle) = y/x
, so y = x*sin(angle)
. Just create an array of x
values however long you want, and then plug it into the formula for the y
values. You'll of course need to round the y
values afterwards. And then you can translate all of them to the starting location for the line.
>>> import numpy as np
>>> angle = 15*np.pi/180
>>> x = np.arange(0,10)
>>> y = np.round(np.sin(angle)*x).astype(int)
>>> [(x,y) for x, y in zip(x, y)]
[(0, 0), (1, 0), (2, 1), (3, 1), (4, 1), (5, 1), (6, 2), (7, 2), (8, 2), (9, 2)]
Post a Comment for "How To Get Value Of Pixels Which Are At A Certain Angle From Another Pixel?"