2D SmoothingΒΆ

This example shows how to use the pylops.Smoothing2D operator to smooth a multi-dimensional input signal along two given axes.

import matplotlib.pyplot as plt
import numpy as np

import pylops


Define the input parameters: number of samples of input signal (N and M) and lenght of the smoothing filter regression coefficients (\(n_{smooth,1}\) and \(n_{smooth,2}\)). In this first case the input signal is one at the center and zero elsewhere.

N, M = 11, 21
nsmooth1, nsmooth2 = 5, 3
A = np.zeros((N, M))
A[5, 10] = 1

Sop = pylops.Smoothing2D(nsmooth=[nsmooth1, nsmooth2], dims=[N, M], dtype="float64")
B = Sop * A.ravel()
B = np.reshape(B, (N, M))

After applying smoothing, we will also try to invert it.

Aest = Sop / B.ravel()
Aest = np.reshape(Aest, (N, M))

fig, axs = plt.subplots(1, 3, figsize=(10, 3))
im = axs[0].imshow(A, interpolation="nearest", vmin=0, vmax=1)
plt.colorbar(im, ax=axs[0])
im = axs[1].imshow(B, interpolation="nearest", vmin=0, vmax=1)
plt.colorbar(im, ax=axs[1])
im = axs[2].imshow(Aest, interpolation="nearest", vmin=0, vmax=1)
axs[2].set_title("Estimated model")
plt.colorbar(im, ax=axs[2])
Model, Data, Estimated model


<matplotlib.colorbar.Colorbar object at 0x7f90d1946e48>

Total running time of the script: ( 0 minutes 0.343 seconds)

Gallery generated by Sphinx-Gallery