See my original post on stackoverflow: First Approach: To find the axis and with that the angle of your line I suggest to use a PCA on the non-zero values: As usually this function could also be written as one-liner: And here is an example: Note that for highly noisy data or images with no clear orientation this method will come up with arbitrary rotations. And here is an example output: Second Approach: Ok after clarification of the actual task in a more complicated setting (see comments) here a second approach based on template matching:Read More →