title: Python Image distortion
body: <p>I'm trying to apply a ripple effect to an image in python.
  I found Pillow's im.transform(im.size, Image.MESH,.... is it possible? 
  Maybe I have to load the image with numpy and apply the algorithm.
  I also found this: <a href="http://www.pygame.org/project-Water+Ripples-1239-.html" rel="noreferrer">http://www.pygame.org/project-Water+Ripples-1239-.html</a></p>
  
  <p><img src="https://i.stack.imgur.com/iIWa0.png" alt="ripple"></p>
  
  <p>another way manually but I don't know any algorithm. this is my start. it doesn't do anything...</p>
  
  <pre><code>    #!/usr/bin/env python3
  
      from PIL import Image
      import sys
      import numpy
      import math
  
      im = Image.open(sys.argv[1])
      im.show()
  
      matrix = numpy.asarray(im)
      width = im.size[0]
      height = im.size[1]
      amplitude = ? # parameters
      frequency = ?
      matrix_dest = numpy.zeros((im.size[0],im.size[1],3))
  
      for x in range(0, width):
          for y in range(0, height):
              pass # ç_ç
  
      im2 = Image.fromarray(numpy.uint8(matrix_dest))
      im2.show()
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'd really like to keep this structure (using pillow. I already use extensivly in my project and if I can I wouldn't add any other dependency) and not including scipi or matplotlib..
  With the following code I have the distortion I wanted, but <strong>colors</strong> are screwed up.
  Maybe I have to apply the distortion to <strong>R,G,B planes</strong> and then compose the result in one image. 
  Or <strong>palettize</strong> the image and then apply the original palette.</p>
  
  <p>(Btw the image would be used as a texture to display moving water in a 3D environment.)</p>
  
  <pre><code>im = Image.open(sys.argv[1])
  im.show()
  
  m = numpy.asarray(im)
  m2 = numpy.zeros((im.size[0],im.size[1],3))
  width = im.size[0]
  height = im.size[1]
  
  A = m.shape[0] / 3.0
  w = 1.0 / m.shape[1]
  
  shift = lambda x: A * numpy.sin(2.0*numpy.pi*x * w)
  
  for i in range(m.shape[0]):
      print(int(shift(i)))
      m2[:,i] = numpy.roll(m[:,i], int(shift(i)))
  
  im2 = Image.fromarray(numpy.uint8(m2))
  im2.show()
  </code></pre>