Multivariate spline interpolation in python/scipy?

If I’m understanding your question correctly, your input “observation” data is regularly gridded? If so, scipy.ndimage.map_coordinates does exactly what you want. It’s a bit hard to understand at first pass, but essentially, you just feed it a sequence of coordinates that you want to interpolate the values of the grid at in pixel/voxel/n-dimensional-index coordinates. As … Read more

How do I choose an image interpolation method? (Emgu/OpenCV)

Nearest neighbor will be as fast as possible, but you will lose substantial information when resizing. Linear interpolation is less fast, but will not result in information loss unless you’re shrinking the image (which you are). Cubic interpolation (probably actually “Bicubic”) uses one of many possible formulas that incorporate multiple neighbor pixels. This is much … Read more

Speedup scipy griddata for multiple interpolations between two irregular grids

There are several things going on every time you make a call to scipy.interpolate.griddata: First, a call to sp.spatial.qhull.Delaunay is made to triangulate the irregular grid coordinates. Then, for each point in the new grid, the triangulation is searched to find in which triangle (actually, in which simplex, which in your 3D case will be … Read more

How to perform bilinear interpolation in Python

Here’s a reusable function you can use. It includes doctests and data validation: def bilinear_interpolation(x, y, points): ”’Interpolate (x,y) from values associated with four points. The four points are a list of four triplets: (x, y, value). The four points can be in any order. They should form a rectangle. >>> bilinear_interpolation(12, 5.5, … [(10, … Read more

In Ruby, can you perform string interpolation on data read from a file?

I think this might be the easiest and safest way to do what you want in Ruby 1.9.x (sprintf doesn’t support reference by name in 1.8.x): use Kernel.sprintf feature of “reference by name”. Example: >> mystring = “There are %{thing1}s and %{thing2}s here.” => “There are %{thing1}s and %{thing2}s here.” >> vars = {:thing1 => … Read more