A collection of sloppy snippets for scientific computing and data visualization in Python.

Wednesday, August 10, 2011

Applying a Moebius transformation to an image

The Moebius transformation is defined as

where z is a complex variable different than -d/c. And a, b, c, d are complex numbers.
In this post we will see how to apply the Moebius transform to an image.
Given a set of three distinct points on the complex plane z1, z2, z3 and a second set of distinct points w1, w2, w3, there exists precisely one Moebius transformation f(z) which maps the zs to the ws. So, in the first step we have to determine f(z) from the given sets of points. We will use the explicit determinant formula to compute the coefficients:

As we can see, the result of the transformation has some empty areas that we should fill using interpolation. So let's look to another way to implement a geometric transformation on an image. The following code uses the scipy.ndimage.geometric_transform to implement the inverse Moebius transform:

Hi Alemi, thanks for your interest.In your gist you have lost a portion of the result, you should consider to use the parameter output_shape of the ndimage.geometric_transform.By the way, could I post your code here?