In [2]:
%matplotlib inline
In [3]:
from numpy import array
import matplotlib.pyplot as plt
import seaborn as sns
In [4]:
from showit import image, tile
import matplotlib.animation as animation
In [5]:
from os.path import join, exists
from os import mkdir, makedirs
In [6]:
#from mesoscope.utils import normalize
In [7]:
import thunder
In [8]:
from registration import CrossCorr
In [9]:
directory = '/tier2/freeman/Nick/sessions'
In [10]:
key = '000222'
prefix = 'trial'
path = directory + '/' + key
print path
print exists(path)
In [11]:
data = thunder.images.fromtif(path + '/images', engine=None)
In [12]:
data
Out[12]:
In [1]:
from mesoscope import reference
In [13]:
ref = reference(data)
In [14]:
fig = plt.figure(figsize=[10,10])
ax = plt.axes()
im = image(ref, clim=(0, 3.5*ref.mean()), ax=ax)
In [15]:
ref.shape
Out[15]:
In [ ]:
In [16]:
algorithm = CrossCorr(axis=0)
In [17]:
model = algorithm.fit(data, reference)
In [18]:
registered = model.transform(data)
In [19]:
registered
Out[19]:
In [20]:
shifts = model.toarray()
In [21]:
shifts.shape
Out[21]:
In [22]:
[plt.plot(model.toarray()[:,i]) for i in range(shifts.shape[1])];
plt.xlim([0, 1000])
Out[22]:
In [23]:
mean = registered.mean().toarray()
In [24]:
mean.shape
Out[24]:
In [25]:
img = mean[0]
fig = plt.figure(figsize=[10,10])
ax = plt.axes()
im = image(img, clim=(0, 3.5*img.mean()), ax=ax)
In [26]:
if not exists(path + '/registered'):
makedirs(path + '/registered')
registered.tobinary(path + '/registered', overwrite=True)
In [27]:
if not exists(path + '/summary'):
makedirs(path + '/summary')
In [28]:
from skimage.io import imsave
imsave(path + '/summary/registered.tif', mean.astype('float32'), plugin='tifffile', photometric='minisblack')
imsave(path + '/summary/reference.tif', reference.astype('float32'), plugin='tifffile', photometric='minisblack')
In [29]:
imsave(path + '/summary/registered-norm.tif', normalize(mean).astype('float32'), plugin='tifffile', photometric='minisblack')
imsave(path + '/summary/reference-norm.tif', normalize(reference).astype('float32'), plugin='tifffile', photometric='minisblack')