Ejemplo n.º 1
0
plt.imshow(fovs)

#%% create a denoised version of the movie, nice to visualize
if True:
    m2=m.copy()
    m2.IPCA_denoise(components = 100, batch = 1000)
    m2.playMovie(frate=.05,magnification=4,gain=10.0)
    
#%%
    

#%% compute spatial components via NMF
initTime=time.time()
space_spcomps,time_comps=m.NonnegativeMatrixFactorization(n_components=20,beta=1,tol=5e-7);
print 'elapsed time:' + str(time.time()-initTime) 
matrixMontage(np.asarray(space_spcomps),cmap=plt.cm.gray) # visualize components

#%% compute spatial components via ICA PCA
initTime=time.time()
spcomps=m.IPCA_stICA(components=10,mu=.5);
print 'elapsed time:' + str(time.time()-initTime) 
matrixMontage(spcomps,cmap=plt.cm.gray) # visualize components
 
#%% extract ROIs from spatial components 
#_masks,masks_grouped=m.extractROIsFromPCAICA(spcomps, numSTD=6, gaussiansigmax=2 , gaussiansigmay=2)
_masks,_=m.extractROIsFromPCAICA(spcomps, numSTD=10.0, gaussiansigmax=1 , gaussiansigmay=1)
matrixMontage(np.asarray(_masks),cmap=plt.cm.gray)

#%%  extract single ROIs from each mask
minPixels=5;
maxPixels=2500;
Ejemplo n.º 2
0
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:
    totalShifts=np.sum(np.asarray(shifts),axis=0)[:,0:2].tolist()
    m=XMovie(mat=np.load(filename_py)['mov'], frameRate=np.load(filename_py)['frameRate']); 
    m.applyShifstToMovie(totalShifts)
#%% apply shifts to another channel, you need to reload the original movie other channel (mov_other_channel)
if False:    
    # here reload the original imaging channel from movie
    totalShifts=np.sum(np.asarray(shifts),axis=0)[:,0:2].tolist()
    mov_other_channel.applyShifstToMovie(totalShifts)

#%% plot movie median
minBrightness=5;
maxBrightness=500;
plt.imshow(np.median(m.mov,axis=0),cmap=plt.cm.Greys_r,vmin=minBrightness,vmax=maxBrightness)