how to deform an image deforming the coordinates
<p>I would like to see how an image get deformed if I know how its coordinates are deformed.</p>

<p>for example: here I draw a circle</p>

<pre><code>import numpy as np
import matplotlib.pyplot as plt
from math import *

plane_side = 500.0 #arcsec

y_l, x_l, = np.mgrid[-plane_side:plane_side:1000j, -plane_side:plane_side:1000j]

r = np.sqrt(y_l**2 + x_l**2)

indexes1 = np.where(r&lt;150.0)
indexes2 = np.where(r&gt;160.0)

image = r.copy()
image[:,:] = 1.0
image[indexes1] = 0.0
image[indexes2] = 0.0

imgplot = plt.imshow(image,cmap="rainbow")
plt.colorbar()
plt.show()
</code></pre>

<p>If I want to deform the coordinates like this:</p>

<pre><code>y_c = y_lense**3
x_c = x_lense**2
</code></pre>

<p>and plot the image distorted, what should I do?</p>

<p>You can use <code>plt.pcolormesh()</code>:</p>

<pre><code>y_c = (y_l/plane_side)**3
x_c = (x_l/plane_side)**2

ax = plt.gca()
ax.set_aspect("equal")
plt.pcolormesh(x_c, y_c, image, cmap="rainbow")
ax.set_xlim(0, 0.2)
ax.set_ylim(-0.1, 0.1);
</code></pre>

<p>the result:</p>

<p><a href="http://i.stack.imgur.com/7NpJw.png" rel="nofollow"><img src="http://i.stack.imgur.com/7NpJw.png" alt="enter image description here"></a></p>

python python-2.7 numpy matplotlib