# Bilinear Interpolation#

This example shows how to use the `pylops.signalprocessing.Bilinar` operator to perform bilinear interpolation to a 2-dimensional input vector.

```import matplotlib.pyplot as plt
import numpy as np
from scipy import misc

import pylops

plt.close("all")
np.random.seed(0)
```

First of all, we create a 2-dimensional input vector containing an image from the `scipy.misc` family.

```x = misc.face()[::5, ::5, 0]
nz, nx = x.shape
```
```/home/docs/checkouts/readthedocs.org/user_builds/pylops/checkouts/latest/examples/plot_bilinear.py:19: DeprecationWarning: scipy.misc.face has been deprecated in SciPy v1.10.0; and will be completely removed in SciPy v1.12.0. Dataset methods have moved into the scipy.datasets module. Use scipy.datasets.face instead.
x = misc.face()[::5, ::5, 0]
```

We can now define a set of available samples in the first and second direction of the array and apply bilinear interpolation.

```nsamples = 2000
iava = np.vstack(
(np.random.uniform(0, nz - 1, nsamples), np.random.uniform(0, nx - 1, nsamples))
)

Bop = pylops.signalprocessing.Bilinear(iava, (nz, nx))
y = Bop * x
```

At this point we try to reconstruct the input signal imposing a smooth solution by means of a regularization term that minimizes the Laplacian of the solution.

```D2op = pylops.Laplacian((nz, nx), weights=(1, 1), dtype="float64")

xinv = pylops.optimization.leastsquares.normal_equations_inversion(
Bop, y, [D2op], epsRs=[np.sqrt(0.1)], **dict(maxiter=100)
)[0]
xinv = xinv.reshape(nz, nx)

fig, axs = plt.subplots(1, 3, figsize=(10, 4))
fig.suptitle("Bilinear interpolation", fontsize=14, fontweight="bold", y=0.95)
axs[0].imshow(x, cmap="gray_r", vmin=0, vmax=250)
axs[0].axis("tight")
axs[0].set_title("Original")