def accumulate(Fo,Fi,par): Fif=Fi+'_fst' Fis=Fi+'_stk' Flow(Fif,Fi,'window f3=0 n3=1') # get first frame Flow(Fis,Fi,'stack axis=3 norm=n') # get stack over time Flow(Fo,[Fif,Fis],''' math x=${SOURCES[0]} y=${SOURCES[1]} output="abs((%d-1)*x-y)/%d" '''%(par['nt'],par['nt'])) Result(Fo,'grey mean=y allpos=y scalebar=y title=""') # jerry-rig to comply with wplot.py part=par print par['oz'] #part['nx']=par['nx'] #part['nz']=par['n2'] #part['dx']=par['d1'] ##part['dz']=par['d2'] #part['ox']=par['o1'] #part['oz']=par['o2'] Result(Fo,wplot.igrey2d('label1=x label2=z allpos=y scalebar=y mean=y',par))
def accumulate(Fo, Fi, par): Fif = Fi + '_fst' Fis = Fi + '_stk' Flow(Fif, Fi, 'window f3=0 n3=1') # get first frame Flow(Fis, Fi, 'stack axis=3 norm=n') # get stack over time Flow( Fo, [Fif, Fis], ''' math x=${SOURCES[0]} y=${SOURCES[1]} output="abs((%d-1)*x-y)/%d" ''' % (par['nt'], par['nt'])) Result(Fo, 'grey mean=y allpos=y scalebar=y title=""') # jerry-rig to comply with wplot.py part = par print par['oz'] #part['nx']=par['nx'] #part['nz']=par['n2'] #part['dx']=par['d1'] ##part['dz']=par['d2'] #part['ox']=par['o1'] #part['oz']=par['o2'] Result(Fo, wplot.igrey2d('label1=x label2=z allpos=y scalebar=y mean=y', par))
def motionmag(Fo, Fi, par): wplot.param(par) # motion magnification parameters nlevel = par['nlevel'] pyr_type = par['pyr_type'] Fband1p = Fi + '_l00' # preprocess video preprocess(Fband1p, Fi, par) plot_level_cube(Fband1p, par, '', 'flat=n title="Original video: tapered "') # first loop over image pyramid levels (downsampling) for i in range(1, nlevel + 1): # next file name tagn = "_l" + "%02d" % i Fband1n = Fi + tagn # no matter the pyramid you must downscale once downscale(Fband1n, Fband1p, 1) #if pyr_type==1: # gaussian pyramid # do nothing (might change later...) if pyr_type == 2: # special case for Laplacian pyramid at highest level if i == nlevel: tagL = "_l" + "%02d" % (i) + '_L' Fband1nL = Fi + tagL downscale(Fband1nL, Fband1p, 1) # save result for now Plot(Fband1nL, wplot.igrey2d('', par)) if i <= nlevel: tagL = "_l" + "%02d" % (i - 1) + '_L' Fband1nL = Fi + tagL # use previous level in the Gaussian pyramid # to form this level of Laplacian Flow(Fband1nL, Fband1p, ' ./sfpyr.x lap=y verb=n up=n boundary=0') # compute next level of the Gaussian pyramid downscale(Fband1n, Fband1p, 1) # save result for now Plot(Fband1nL, wplot.igrey2d('', par)) elif pyr_type != 1: print("pyr_type type not recognized") # save resulting level for testing Plot(Fband1n, wplot.igrey2d('', par)) # swap file names tagp = tagn Fband1p = Fband1n # second loop over image pyramid levels # transpose x and t axis # => bandpass => scale # => transpose x and t axis # => upscale to original size Fmulti1 = [] for i in range(0, nlevel + 1): # previous file name tagp = "_l" + "%02d" % i Fband1p = Fi + tagp Fband1n = Fband1p + '_bs' preflow = ''' transp plane=13 | erf flo=%(fl_Hz)g fhi=%(fh_Hz)g rect=32 | math output=%(alpha)g*input | transp plane=13 ''' % par Flow(Fband1n, Fband1p, preflow) plot_level_cube(Fband1n, par, '', 'flat=n title=""') # save list of filenames to collapse later Fmulti1.append(Fband1n) # collapse pyramid (works for Gaussian only right now) # TODO: collapse a Laplacian pyramid collapse(Fo, Fmulti1, pyr_type) # Optional section: # compute stacked versions of the cube if desired # stack over z and x (first two dimensions) to show time series # and spectrum for each level (w and w/o magnification) go_stack = True if go_stack: # for motion magnified result # stack over z and x then normalize Flow( Fo + '_s', Fo, '''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''') # amplitude spectra Flow( Fo + '_s' + '_f', Fo + '_s', '''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''') # save what you want here Plot(Fo + '_s', 'graph title=' ' plotfat=3 plotcol=3') Plot(Fo + '_s' + '_f', 'cabs | graph title=' ' plotfat=3 plotcol=3') # for each level of the pyramid for i in range(0, nlevel + 1): # previous files tagp = "_l" + "%02d" % i + "_bs" tagl = "_l" + "%02d" % i Fband1p = Fi + tagp Fband1l = Fi + tagl # next files Fband1n = Fband1p + '_s' Fband1nf = Fband1n + '_f' Fband1nl = Fband1l + '_s' Fband1nlf = Fband1nl + '_f' # stack over z and x then normalize Flow( Fband1n, Fband1p, '''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''') Flow( Fband1nl, Fband1l, '''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''') # amplitude spectra Flow( Fband1nf, Fband1n, '''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''') Flow( Fband1nlf, Fband1nl, '''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''')
def motionmag(Fo,Fi,par): wplot.param(par) # motion magnification parameters nlevel =par['nlevel'] pyr_type=par['pyr_type'] Fband1p=Fi+'_l00' # preprocess video preprocess(Fband1p,Fi,par) plot_level_cube(Fband1p,par,'','flat=n title="Original video: tapered "') # first loop over image pyramid levels (downsampling) for i in range(1,nlevel+1): # next file name tagn = "_l"+"%02d"%i Fband1n=Fi+tagn # no matter the pyramid you must downscale once downscale(Fband1n,Fband1p,1) #if pyr_type==1: # gaussian pyramid # do nothing (might change later...) if pyr_type==2: # special case for Laplacian pyramid at highest level if i==nlevel: tagL = "_l"+"%02d"%(i)+'_L' Fband1nL=Fi+tagL downscale(Fband1nL,Fband1p,1) # save result for now Plot(Fband1nL,wplot.igrey2d('',par)) if i<=nlevel: tagL = "_l"+"%02d"%(i-1)+'_L' Fband1nL=Fi+tagL # use previous level in the Gaussian pyramid # to form this level of Laplacian Flow(Fband1nL,Fband1p,' ./sfpyr.x lap=y verb=n up=n boundary=0') # compute next level of the Gaussian pyramid downscale(Fband1n,Fband1p,1) # save result for now Plot(Fband1nL,wplot.igrey2d('',par)) elif pyr_type!=1: print("pyr_type type not recognized") # save resulting level for testing Plot(Fband1n, wplot.igrey2d('',par)) # swap file names tagp=tagn Fband1p=Fband1n # second loop over image pyramid levels # transpose x and t axis # => bandpass => scale # => transpose x and t axis # => upscale to original size Fmulti1=[] for i in range(0,nlevel+1): # previous file name tagp = "_l"+"%02d"%i Fband1p=Fi+tagp Fband1n=Fband1p+'_bs' preflow=''' transp plane=13 | erf flo=%(fl_Hz)g fhi=%(fh_Hz)g rect=32 | math output=%(alpha)g*input | transp plane=13 '''%par Flow(Fband1n,Fband1p,preflow) plot_level_cube(Fband1n,par,'','flat=n title=""') # save list of filenames to collapse later Fmulti1.append(Fband1n) # collapse pyramid (works for Gaussian only right now) # TODO: collapse a Laplacian pyramid collapse(Fo,Fmulti1,pyr_type) # Optional section: # compute stacked versions of the cube if desired # stack over z and x (first two dimensions) to show time series # and spectrum for each level (w and w/o magnification) go_stack=True if go_stack: # for motion magnified result # stack over z and x then normalize Flow(Fo+'_s',Fo,'''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''' ) # amplitude spectra Flow(Fo+'_s'+'_f',Fo+'_s','''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''') # save what you want here Plot(Fo+'_s' ,'graph title='' plotfat=3 plotcol=3') Plot(Fo+'_s'+'_f','cabs | graph title='' plotfat=3 plotcol=3') # for each level of the pyramid for i in range(0,nlevel+1): # previous files tagp = "_l"+"%02d"%i+"_bs" tagl = "_l"+"%02d"%i Fband1p =Fi+tagp Fband1l =Fi+tagl # next files Fband1n =Fband1p+'_s' Fband1nf =Fband1n+'_f' Fband1nl =Fband1l+'_s' Fband1nlf=Fband1nl+'_f' # stack over z and x then normalize Flow(Fband1n ,Fband1p,'''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''' ) Flow(Fband1nl,Fband1l,'''stack axis=1 norm=n | stack axis=1 norm=n | put label1=time unit1=s label2=intensity unit2='' ''' ) # amplitude spectra Flow(Fband1nf,Fband1n,'''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''') Flow(Fband1nlf,Fband1nl,'''fft1 | put label1=frequency unit1=Hz label2=amplitude unit2='' ''')