title: Scale 2D-Array using Bicubic Interpolation
body: <p>I want to scale an arbitrary <code>double[][]</code> to another <code>double[][]</code> with different dimensions. The values of the resulting array should be calculated based on the input array using bicubic interpolation.</p>
  
  <p>I know this was done in image processing for decades now, but I was unable to find a library or at least a working code snippet that works for any 2d-array rather than some specific image objects, so that's why I'm asking here.</p>
  
  <p>More specific requirements:</p>
  
  <p>As far as I've understood, the value of any point between the corners of a 3x3-grid can be calculated directly using bicubic interpolation, so the first function I would need is something like </p>
  
  <pre><code>double interpolate(double[][] grid3by3, double x, double y)`
  </code></pre>
  
  <p>where x and y are between 0.0 and 1.0</p>
  
  <p>The next step would of course be to ease this process so the 3x3 grid is chosen for every point automatically and I can get something like</p>
  
  <pre><code>`double[][] interpolate(double[][] input, int newWidth, int newHeight)`
  </code></pre>
  
  <p>This will get me a new array with the specified dimensions but with the same borders as the input array.</p>
  
  <p>Where I actually want to get is this:</p>
  
  <pre><code>`double[][] interpolate(double[][] input, int newWidth, int newHeight,
                          double minX, double minY, double maxX, double maxY)`
  </code></pre>
  
  <p>The min and max values define a bounding box so I can get a subset of the initial array which does not necessarily need to start or end at an exact index value of the input array (e.g. a corner can be at (5,3) or (5.25, 3.7), so you can't just cut off the input array at some index value). This bounding box will become the extent of the new array and the values are interpolated from the input array.</p>
  
  <p>Oh, and just FYI: This is about digital elevation models, so please tell me if my approach is totally wrong in the first place ;)</p>