You can tabulate the dof coordinates of your function space (assuming they are a Lagrange space/scalar valued), and use the dolfinx.fem.Function.x.array to Get the values at the corresponding degrees of freedom.
g is a function that takes in an array of coordinates (on the form [[x_0, x_1, ...., x_n], [y_0,..., y_n], [z_0,..,z_n]] and returns a value per [x_i,y_i,z_i] coordinate.
As long as you have a function that can take physical coordinate (x,y,z) and return a value from the image, you can create an interpolation operator.
If someone faces a similar problem, I would note that interp2d was deprecated in the newer scipy releases. The alternative is to use a RegularGridInterpolator, but that would require a little tweak to the function proposed by dokken:
f = RegularGridInterpolator((x, y), z, method='linear')
def g(x):
return f(np.array([x[0], x[1]]).T)
u = fem.Function(V)
u.interpolate(g)