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()


/Users/jesse/Development/Theano/theano/gof/cc.py:944: UserWarning: Your g++ compiler fails to compile OpenMP code. We know this happen with some version of the EPD mingw compiler and LLVM compiler on Mac OS X. We disable openmp everywhere in Theano. To remove this warning set the theano flags `openmp` to False.
  ret += x.c_compile_args()

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))


[ 15.          15.           1.57079637   0.           1.07130682
   2.71828175   2.71828175]

In [4]:
gs = gf.make_gabor(params, 32, 32)
plt.imshow(np.squeeze(gs), cmap='gray')


Out[4]:
<matplotlib.image.AxesImage at 0x117445780>

In [5]:
_, pp, se = gf.fit(gs)

In [6]:
pp = fit.combine_params(*pp)
print(pp)


[  1.49999952e+01   1.50000067e+01   1.57079875e+00  -8.10419897e-06
   1.11072052e+00   1.00000024e+00   1.00000000e+00]

In [7]:
print(params)


[ 15.          15.           1.57079633   0.           1.11072073   1.           1.        ]

In [8]:
se


Out[8]:
array([  2.60572328e-11])

In [9]:
gs = gf.make_gabor(pp, 32, 32)
plt.imshow(np.squeeze(gs), cmap='gray')
plt.axis


Out[9]:
<function matplotlib.pyplot.axis>

Noise


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]:
<matplotlib.legend.Legend at 0x11bc27be0>

In [ ]: