title: Resize using bilinear interpolation in Python
body: <p>I'm trying to manually implement resizing image using bilinear interpolation.
  What I've got so far is a function for the interpolation itself which seems to work fine, but the resize function seems to work properly only on the corners:</p>
  <pre><code>def bilinear_interpolation(image, y, x):
  height = len(image)
  width = len(image[0])
  
  x1 = min(math.floor(x), width - 1)
  y1 = min(math.floor(y), height - 1)
  x2 = min(math.ceil(x), width - 1)
  y2 = min(math.ceil(y), height - 1)
  
  a = image[y1][x1]
  b = image[y2][x1]
  c = image[y1][x2]
  d = image[y2][x2]
  
  new_pixel = a * (1 - x) * (1 - y)
  new_pixel += b * y * (1 - x)
  new_pixel += c * x * (1 - y)
  new_pixel += d * x * y
  return round(new_pixel)
  def resize(image, new_height, new_width):
  
  new_image = [[0 for _ in range(new_width)] for _ in range(new_height)]
  
  for y in range(new_height):
      for x in range(new_width):
          x_ = (x / (new_width - 1)) * len(image[0])
          y_ = (y / (new_height - 1)) * len(image)
  
          new_image[y][x] = bilinear_interpolation(image, y_, x_)
  
  return new_image
  </code></pre>
  <p>So for the matrix:</p>
  <pre><code>[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
  </code></pre>
  <p>I got</p>
  <pre><code>[[1, 4], [9, 12], [13, 16]]
  </code></pre>
  <p>instead of</p>
  <pre><code>[[1, 4], [7, 10], [13, 16]]
  </code></pre>
  <p>Thanks in advance.</p>