# Correcting a spherical photo

I have a set of spherical panoramic images that include roll, pitch and yaw along with the 3d location of the camera in x,y,z. I would like to transform these images such that these rotations are removed and all images have a common orientation. My thinking to do this was as follows;

- Consider each pixel as a point on the surface of a 3d sphere, where the x offset corresponded to horizontal angle, y offset to vertical angle and focal length as radius.
- Convert these spherical coordinates to Cartesian coordinates Create a rotation matrix from the angles provided and use it to rotate these coordinates
- Convert the coordinates back to spherical polar coordinates, which correspond to corrected pixel positions

While this seems to work ok visually, testing it against known coordinates in the same frame comes up with errors. I had hoped this was due to order of application of angles but this seems not to be the case. Is there a better way of doing this?

an example image might be helpful.

also: how did the spherical distortion occur ?

To the best of my knowledge there isn't any distortion, it is simply the pose of the camera I'm correcting for. The pictures are taken from a camera mounted on the roof of a vehicle which may be travelling up or down a hill on a road with camber. I'll put together a detailed example as soon as I get an opportunity,