Example #1
0
plt.imshow(medMov,cmap=plt.cm.Greys_r,vmin=minBrightness,vmax=maxBrightness)

#%% save motion corrected movie inpython format along with the results. This takes some time now but will save  a lot later...
np.savez(filename_mc,mov=m.mov,frameRate=frameRate,templates=templates,shifts=shifts,max_shift=max_shift)

#%% RELOAD MOTION CORRECTED MOVIE
m=XMovie(mat=np.load(filename_mc)['mov'], frameRate=frameRate);    
max_shift=np.load(filename_mc)['max_shift']


#%% crop movie after motion correction. 
m.crop(max_shift,max_shift,max_shift,max_shift)    

#%% if you want to make a copy of the movie
if False:
    m_copy=m.copy()


#%% resize to increase SNR and have better convergence of segmentation algorithms
resizeMovie=True
if resizeMovie:
    fx=.5; # downsample a factor of four along x axis
    fy=.5;
    fz=.1; # downsample  a factor of 5 across time dimension
    m.resize(fx=fx,fy=fy,fz=fx)
else:
    fx,fy,fz=1,1,1

#%% compute delta f over f (DF/F)
initTime=time.time()
m.computeDFF(secsWindow=15,quantilMin=20,subtract_minimum=False)
Example #2
0
for j in range(0,num_iter):
    template_used,shift=m.motion_correct(max_shift_w=max_shift_w,max_shift_h=max_shift_h,template=None,show_movie=False);
    templates.append(template_used)
    shift=np.asarray(shift)
    shifts.append(shift)

plt.plot(np.asarray(shifts).reshape((j+1)*shift.shape[0],shift.shape[1]))

#%% motion correct Cristina
initTime=time.time()

m=XMovie(mat=np.load(filename_py)['mov'], frameRate=np.load(filename_py)['frameRate']); 
m.makeSubMov(range(2000))
m.crop(crop_top=0,crop_bottom=1,crop_left=0,crop_right=0,crop_begin=0,crop_end=0)
m_tmp=m.copy()
_,shift=m_tmp.motion_correct(max_shift_w=60,max_shift_h=20,template=None,show_movie=False);
template=np.median(m_tmp.mov,axis=0)
m_tmp=m.copy()
_,shift=m_tmp.motion_correct(max_shift_w=60,max_shift_h=20,template=template,show_movie=False);
template=np.median(m_tmp.mov,axis=0)

m=XMovie(mat=np.load(filename_py)['mov'], frameRate=np.load(filename_py)['frameRate']); 
m.crop(crop_top=0,crop_bottom=1,crop_left=0,crop_right=0,crop_begin=0,crop_end=0)
_,shifts=m.motion_correct(max_shift_w=100,max_shift_h=20,template=template,show_movie=False);
    
print 'elapsed time:' + str(time.time()-initTime) 
#%%
matrixMontage(np.asarray(templates),cmap=plt.cm.gray,vmin=0,vmax=1000)
#%% apply shifts to original movie in order to minimize smoothing
if False: