Hi there,
I’m trying to develop a bilinear interpolation using dask.
I have this piece of code taken from stack overflow and I changed the numpy calls to dask.array.
def bilinear_interpolate(im: da.Array, uv: tuple) -> da.Array:
u0 = da.floor(uv[0]).astype(np.int32)
u1 = u0 + 1
v0 = da.floor(uv[1]).astype(np.int32)
v1 = v0 + 1
u0 = da.clip(u0, 0, im.shape[1] - 1)
u1 = da.clip(u1, 0, im.shape[1] - 1)
v0 = da.clip(v0, 0, im.shape[0] - 1)
v1 = da.clip(v1, 0, im.shape[0] - 1)
Ia = im[v0, u0]
Ib = im[v1, u0]
Ic = im[v0, u1]
Id = im[v1, u1]
wa = (u1 - uv[0]) * (v1 - uv[1])
wb = (u1 - uv[0]) * (uv[1] - v0)
wc = (uv[0] - u0) * (v1 - uv[1])
wd = (uv[0] - u0) * (uv[1] - v0)
return wa * Ia + wb * Ib + wc * Ic + wd * Id
where im is a dask.array image, and uv is a tuple of dask array coordinates, say (x, y).
The main problem here are these lines:
Ia = im[v0, u0]
Ib = im[v1, u0]
Ic = im[v0, u1]
Id = im[v1, u1]
since dask does not support fancy indexing.
Does anyone know how can I make this work? - One possibility that I don’t like is to compute im
and the coordinates uv
. Is there another way to do this?