title: Image warping with scikit-image and transform.PolynomialTransform
body: <p>I attach a <a href="https://drive.google.com/file/d/0B6EnJ-Vh6zs1MkVCRlNhZkJsOEk/view?usp=sharing" rel="nofollow">zip archive</a> with all the files needed to illustrate and reproduce the problem.</p>
  
  <p>(I don't have permissions to upload images yet...)</p>
  
  <p>I have an image (test2.png in the zip archive ) with curved lines.</p>
  
  <p>I try to warp it so the lines are straight. 
  I thought of using scikit-image transform, and in particular transform.PolynomialTransform because the transformation involves high order distortions.</p>
  
  <p>So first I measure the precise position of each line at regular intervals in x to define the input interest points (in the file source_test2.csv). 
  Then I compute the corresponding desired positions, located along a straight line (in the file destination_test2.csv). </p>
  
  <p>The figure correspondence.png shows how it looks like.</p>
  
  <p>Next, I simply call transform.PolynomialTransform() using a polynomial of order 3.
  It finds a solution, but when I apply it using transform.warp(), the result is crazy, as illustrated in the file Crazy_Warped.png</p>
  
  <p>Anybody can tell what I am doing wrong?
  I tried polynomial of order 2 without luck...
  I managed to get a good transformation for a sub-image (the first 400 columns only).
  Is transform.PolynomialTransform() completely unstable in a case like mine?</p>
  
  <p>Here is the entire code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import asciitable
  import matplotlib.pylab as pylab
  from skimage import io, transform
  
  # read image 
  orig=io.imread("test2.png",as_grey=True)
  # read tables with reference points and their desired transformed positions
  source=asciitable.read("source_test2.csv")
  destination=asciitable.read("destination_test2.csv")
  
  # format as numpy.arrays as required by scikit-image
  # (need to add 1 because I started to count positions from 0...)
  source=np.column_stack((source["x"]+1,source["y"]+1))
  destination=np.column_stack((destination["x"]+1,destination["y"]+1))
  # Plot
  plt.imshow(orig, cmap='gray', interpolation='nearest')
  plt.plot(source[:,0],source[:,1],'+r')
  plt.plot(destination[:,0],destination[:,1],'+b')
  plt.xlim(0,orig.shape[1])
  plt.ylim(0,orig.shape[0])
  
  # Compute the transformation
  t = transform.PolynomialTransform()
  t.estimate(destination,source,3)
  
  # Warping the image
  img_warped = transform.warp(orig, t, order=2, mode='constant',cval=float('nan'))
  
  # Show the result
  plt.imshow(img_warped, cmap='gray', interpolation='nearest')
  plt.plot(source[:,0],source[:,1],'+r')
  plt.plot(destination[:,0],destination[:,1],'+b')
  plt.xlim(0,img_warped.shape[1])
  plt.ylim(0,img_warped.shape[0])
  # Save as a file
  io.imsave("warped.png",img_warped)
  </code></pre>
  
  <p>Thanks in advance!</p>