Skip to content

Instantly share code, notes, and snippets.

@mehdidc
Last active September 2, 2017 11:34
Show Gist options
  • Save mehdidc/09ce1aa8fe8d4e02e89cad27bf0861c9 to your computer and use it in GitHub Desktop.
Save mehdidc/09ce1aa8fe8d4e02e89cad27bf0861c9 to your computer and use it in GitHub Desktop.
from sklearn.svm import SVR
def smooth_image(x, y, z, w=100, h=100, model=SVR()):
X = np.vstack((x, y)).T
model.fit(X, z)
x, y = np.meshgrid(
np.linspace(x.min(), x.max(), w),
np.linspace(y.min(), y.max(), h)
)
x = x.flatten()
y = y.flatten()
xs = np.vstack((x, y)).T
zs = model.predict(xs)
zs = zs.reshape((w, h))
return zs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment