title: Python - Bilinear image interpolation
body: <p>I'm trying to write a Python function that takes an image as input and performs bilinear image interpolation to resize an image. I've had reasonable success, since the image does get resized, but the process introduces black holes in the output which I can't seem to figure out how or why they're there.</p>
  
  <p>The questions I've seen haven't helped me much (<a href="https://stackoverflow.com/questions/12729228/simple-efficient-bilinear-interpolation-of-images-in-numpy-and-python">Simple, efficient bilinear interpolation of images in numpy and python</a>)</p>
  
  <p>The code:</p>
  
  <pre><code>def img_interp(img, scale = 1.5):
  
      angle_rad = pi * angle_deg / 180.0;
  
      rows, cols, colours = img.shape
  
      n_rows = int(round(rows * scale, 0))
      n_cols = int(round(cols * scale, 0))
  
      enlarged_img = np.ones((n_rows, n_cols, colours))
  
      for i in range(n_rows - 1):
          for j in range(n_cols - 1):
              x_coord = j / scale
              y_coord = i / scale
  
              xc = int(ceil(x_coord))
              xf = int(floor(x_coord))
              yc = int(ceil(y_coord))
              yf = int(floor(y_coord))
  
              W_xc = xc - x_coord
              W_xf = x_coord - xf
              W_yc = yc - y_coord
              W_yf = y_coord - yf
  
             enlarged_img[i, j, :] = 255 - np.around(W_xc * (W_yc * img[yf, xf, :] + W_yf * img[yc, xf, :]) + W_xf * (W_yc * img[yf, xc, :] + W_yf * img[yc, xc, :]), 0)
  
      return enlarged_img
  </code></pre>
  
  <p>The image results:
  <a href="https://www.dropbox.com/s/ji0frbzcuyxd11u/results.png?m=" rel="nofollow">https://www.dropbox.com/s/ji0frbzcuyxd11u/results.png?m=</a></p>
  
  <p>There are probably better ways to do this than what I've done, but I would really appreciate it if someone could have a look and tell me what I did wrong or what I still need to do. Thanks!</p>