Quick experiment in making tinyplanet images from non-ideal panoramas.
In order to make a good tinyplanet image, you normally need a level horizon, otherwise your planet will have an unsightly fault:
An uneven horizon may be due to the camera not being entirely level throughout the taking of the photo, or the panorama may contain uneven ground, and not be exactly 360º.
If the height difference between the ends of the horizon is great enough, simply rotating the whole image to fit causes extreme wonkiness in the output.
The technique used here gradually corrects the horizon alignment from the centre of the image to a mid-point between the two ends of the horizon. This produces a better result.
Uses the technique described here:
LITTLE PLANET PHOTOS: 5 SIMPLE STEPS TO MAKING PANORAMA WORLDS
Code for the polar distort originally from a Stack Overflow answer: Image to polar co-ordinates
Another command-line tinyplanet generator from Fred's ImageMagick Scripts
Consider using a seam carving technique to detect the horizon https://avikdas.com/2019/05/14/real-world-dynamic-programming-seam-carving.html