Simplified question
How do you convert a spherical coordinate (θ, φ) into a position (x, y) on an equirectangular projection (also called 'geographic projection')?
In which:
- x is longitude, the horizontal position, from -180 to 180 degrees.
- y is latitude, the vertical position, from -90 to 90 degrees.
- θ is theta, the horizontal angle in degrees, a vector from (0,0,0) to a point on the surface of a sphere.
- φ is phi, the vertical angle in degrees, a vector from (0,0,0) to a point on the surface of a sphere.
Below you find the original question, back when I did not understand the problem well, but I think that it is still good for showing what is a practical application of this solution.
Context
Edit: The original question title was: How to transform a photo at a given angle to become a part of a panorama photo?
Can anybody help me with which steps I should take if I want to transform a photo taken at any given angle in such a way that I can place the resulting (distorted/transformed) image at the corresponding specific location on an equirectangular projection, cube map, or any panorama photo projection?
Whichever projection is easiest to do is good enough, because there are plenty of resources on how to convert between different projections. I just don't know how to do the step from an actual photo to such a projection.
It is safe to assume that the camera will stay at a fixed location, and can rotate in any direction from there. The data that I think is required to do this, is probably something like this:
- Horizontal angle of physical camera
[-180, +180]
(e.g. +140deg). - Vertical angle of physical camera
[-90, +90]
(e.g. -30deg). - Resolution of photo
w x h
(e.g. 1280x720 pixels). - Horizontal angle of photo (e.g. 70deg).
- Vertical angle of photo (e.g. 40deg).
- Lens correction a, b, c parameters (see below).
I have this data, and I guess the first step is to do lens correction so that all lines that should be straight are in fact straight. And this can be done using imagemagick
's Barrel Distortion, in which you only need to fill in three parameters: a, b, and c. The transformation that is applied to the image to correct this is straightforward.
I am stuck on the next step. Either I do not fully understand it, or search engines are not helping me, because most results are about converting between already given projections or use advanced applications to stitch photos intelligently together. These results did not help me with answering my question.
EDIT: I figured that maybe a figure will help explaining it better :)
The problem is that a given photo Red cannot be placed into the equirectangular projection without a transformation. The figure below illustrates the problem.
So, I have Red, and I need to transform it into Green. Blue shows the difference in transformation, but this depends on the horizontal/vertical angle.