I need for an algorithm which do steps, displayed on image below. Are solutions for doing this exist? (Preferably on C# or JavaScript).
2 Answers
You could try detecting line segments in the image for example using hough transform, or maybe lswms, edlines or lsd.
After detecting the lines, you can compute their length and angle and find the longest almost horizontal line. If you are lucky, this line will be the horizon and you can rotate the whole image in the opposite direction to get the aligned image.
This might work but it will depend on how good the horizon is visible and how well it is detected.
Maybe you could find a number of potential horizon lines and have the user select the best one.
On second thought, if you involve users into this, just let them draw the horizon and then rotate the image. That's not really what you were asking for, but it will probably work better than what I suggested above. :)
I'm not expert in image processing, but if I had to try something I would
1) convert the image to grayscale
2) do some denoising (maybe with a median filter) and thresholding
3) use principal component analysis to find the orientation
-
1$\begingroup$ There is no reason to think that the horizon is going to dominate the principle components. $\endgroup$ Aug 1, 2013 at 22:31