Line detection is easy with python's scikit-image
using radon
transformation
The sinogram, comprises a set of 1-D projections at various angles, each row of the sinogram contains one projection. The brightest parts of the sinogram correspond to the white area in the original image. The brighter the area in sinogram, the greater the collinearity of the objects in the original image. We assume that the coordinates of the sinogram’s maximum value relate to a straight line. Let's use radon
transformation and plot the sinogram.
sinogram = radon(blank)
plt.title("Radon transform\n(Sinogram)")
plt.xlabel("Projection angle (deg)")
plt.ylabel("Projection position (pixels)")
plt.imshow(sinogram, cmap='gray')
plt.show()
We can see the brightest spot at 45 degrees (horizontal axis) and centered around row pixel=50 (vertical axis)
Find the RMS value of each row and find brightest rotation, where the transform is lined up perfectly with the line
r = np.array([np.sqrt(np.mean(np.abs(line) ** 2)) for line in sinogram.transpose()])
angle = np.argmax(r)
print('Angle: {:.1f} degrees'.format(90 - angle))
It outputs
Angle: 45.0 degrees
Similarly you can find pixel value on vertical axis