Tiny Planet Algorithm? So I've recently been looking at the Tiny Planet images.
I've been googling a few things to try and find out how images are converted from normal to a tiny planet. Some phone apps, as well as photoshop do this.
I think Photoshop does it by converting Cartesian coordinates to Polar coordinates.
I found a good explanation of converting them here.
However, I am yet to find somewhere that describes an algorithm of the process.
Is there a set formula? or is it more complex than that?
I'm not sure if it's as easy as moving pixels and converting coordinates because I think some form of stretching must be included... hence, looking for an algorithm and this exchange as a resource. Thanks.
 A: DISCLAIMER: I'm not sure if this is the original Photoshop algorithm but this looks pretty good to me.
If you have a spherical panoramic photo like this (original photo taken by Javierdebe, on flickr)

and you want to have this

all you have to do is to figure out each pixel on the target picture comes from which pixel on the original picture.
I added some (ugly) grid lines on the photos to better illustrate how the transformation can be done. Note that the longitude lines (the black lines) remain straight, and the latitude lines (the yellow lines) become circles, and the distance between the latitude lines remain the same (which is a big assumption). The bottom edge of the original photo shrinks to a point at the center of the target image. The left edge and the right edge meet at 6 o'clock of the target image.
If we create a polar coordinate system whose origin is at the center of the target image, and the polar axis points upward (the red line) we can easily get the polar coordinate (r, θ) of each pixel (x', y') in the target image (Note that the origin of the cartessian coordinate is at the top-left corner, and the y'-axis points downward).
$$
r = \sqrt{(H - x')^2 + (H - y')^2}
$$
$$
\theta = tan^{-1}\frac{H - x'}{H - y'}
$$
where H is the height of the original image, and is also the radius of the target image.
From that we can work out the coordinate (x, y) of the corresponding pixel in the original image.
$$
x = \frac{\pi - \theta}{2\pi}W
$$
$$
y = H - r
$$
where W is the width of the original image
The rest is simple. Just loop over each pixel in the target image area, and grab the color from the corresponding pixel in the original image.
Here is a piece of Ruby code (with RMagick), not optimized, so it's a bit slow
#!/usr/bin/env ruby
require 'rmagick'

TWO_PI = 2 * Math::PI

image_path = ARGV[0]   # Path to the original spherical panorama photo
planet_path = ARGV[1]  # Path to the tiny planet image

original = Magick::Image.read(image_path).first  # Load original image
width = original.columns
height = original.rows

target_size = height * 2
planet = Magick::Image.new(target_size, target_size)  # Create a square canvas

target_size.times do |x|
  target_size.times do |y|
    r, θ = Complex(height - y, height - x).polar  # Cheat using complex plane
    next if r > height  # Ignore the pixels outside the circle
    x_original = width / 2 - θ * width / TWO_PI
    y_original = height - r
    color = original.pixel_color(x_original, y_original)  # Grab the color from original image
    planet.pixel_color(x, y, color)  # Apply the color to the planet image
  end
end

planet.write(planet_path)

A: The process of creating the images you describe uses a kind of projection called stereographic projection. When you take your panorama photo, it "stores" the data on a sphere so to speak.
$\hspace{45mm}$
Our goal is to project that image from the sphere to the plane.
$\hspace{25mm}$
As you can see in the image above, the projection of a point is found by taking a line from the north pole through the point you wish to project and finding its intersection with the $z=-1$ plane. Mathematically, this translates to finding a $t$ such that
$$\begin{pmatrix}0 \\ 0 \\ 1\end{pmatrix}+t\left(\begin{pmatrix}x \\ y \\ z\end{pmatrix}-\begin{pmatrix}0 \\ 0 \\ 1\end{pmatrix}\right)=\begin{pmatrix}X \\ Y \\ -1\end{pmatrix},t\in\mathbb{R}$$
Here $(x,y,z)$ is the point we wish to project and $(X,Y)$ is the resulting projection. Now, if we look only at the $z$ coordinate, this boils down to solving the following equation
$$1+t(z-1)=-1$$
which has the nice and simple soltuion
$$t=\frac{2}{1-z}$$
Plugging back into our first equation we get
$$\begin{pmatrix}\frac{2x}{1-z} \\ \frac{2y}{1-z} \\ -1\end{pmatrix}=\begin{pmatrix}X \\ Y \\ -1\end{pmatrix}$$
Therefore, the coordinates for the projection is
$$(X,Y)=\left(\frac{2x}{1-z},\frac{2y}{1-z}\right)$$
Now, I don't know how the camera's actually store the data for the panorama, but assuming you have access to such an image you can transform that data onto the sphere and apply the projection to get your desired result.
Image source
A: The article you have linked has "Stereographic Projection" in the title. Here is a link to the relevant part of the Wikipedia article. It is difficult to tell solely from looking at the images, but it seems as if the original photograph (which is a effectively a portion of a plane) is mapped to a hemisphere using a similar transformation. Then, in a second transformation, each point $(x,y,z)$ of the hemisphere is mapped to $(x,y,0)$ so that all of the points lie in a plane. It seems to me that this would create the desired effect.
