In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from gabor_fit import fit
import theano
In [2]:
gf = fit.GaborFit()
In [3]:
# x, y, theta, phi, lkx, lvx, lvy
params = np.array([15., 15., np.pi/2., 0., 2.*np.pi/2.8284271247461903 / 2., 1., 1.])
print(fit.standardize_params(params))
In [4]:
gs = gf.make_gabor(params, 32, 32)
plt.imshow(np.squeeze(gs), cmap='gray')
Out[4]:
In [5]:
_, pp, se = gf.fit(gs)
In [6]:
pp = fit.combine_params(*pp)
print(pp)
In [7]:
print(params)
In [8]:
se
Out[8]:
In [9]:
gs = gf.make_gabor(pp, 32, 32)
plt.imshow(np.squeeze(gs), cmap='gray')
plt.axis
Out[9]:
In [41]:
nse = []
fse = []
rse = []
for std in np.logspace(-6, 0, 10):
gsp = gs + np.random.randn(*gs.shape) * std
gsp = gsp / np.sqrt(np.square(gsp).sum())
f, (ax0, ax1) = plt.subplots(1, 2)
ax0.imshow(np.squeeze(gsp), cmap='gray')
nse.append(np.square(gsp-gs).sum())
_, pp, se = gf.fit(gsp)
pp = fit.combine_params(*pp)
gspp = gf.make_gabor(pp, 32, 32)
ax1.imshow(np.squeeze(gspp), cmap='gray')
rse.append(np.square(gspp-gs).sum())
fse.append(se)
In [42]:
plt.figure()
plt.plot(nse, fse, label='fit')
plt.xscale('log')
plt.yscale('log')
plt.plot([min(nse), max(nse)], [min(nse), max(nse)], label='x=y')
plt.xlabel('added noise squared-error')
plt.ylabel('fit squared-error')
plt.legend()
plt.figure()
plt.plot(nse, rse, label='recovery')
plt.xscale('log')
plt.yscale('log')
plt.plot([min(nse), max(nse)], [min(nse), max(nse)], label='x=y')
plt.xlabel('added noise squared-error')
plt.ylabel('recovery squared-error')
plt.legend()
Out[42]:
In [ ]: