def plot_level_cube(Fin,par=dict(),custombyte='',customgrey3=' title=""'): wplot.param(par) frame1=par['nx']/2.0 frame2=par['nz']/2.0 # index not coordinate frame3=par['ot'] # good for all positive between zero and one #Result(Fin,' byte pclip=100 gainpanel=a allpos=y scalebar=y ' + custombyte + ' bar=bar.rsf | grey3 scalebar=y bar=bar.rsf ' + customgrey3 + ' frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3); Result(Fin,' byte pclip=100 scalebar=y ' + custombyte + ' bar=bar.rsf | grey3 scalebar=y bar=bar.rsf ' + customgrey3 + ' frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3);
def plot_level_cube(Fin, par=dict(), custombyte='', customgrey3=' title=""'): wplot.param(par) frame1 = par['nx'] / 2.0 frame2 = par['nz'] / 2.0 # index not coordinate frame3 = par['ot'] # good for all positive between zero and one #Result(Fin,' byte pclip=100 gainpanel=a allpos=y scalebar=y ' + custombyte + ' bar=bar.rsf | grey3 scalebar=y bar=bar.rsf ' + customgrey3 + ' frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3); Result( Fin, ' byte pclip=100 scalebar=y ' + custombyte + ' bar=bar.rsf | grey3 scalebar=y bar=bar.rsf ' + customgrey3 + ' frame1=%d ' % frame1 + ' frame2=%d ' % frame2 + ' frame3=%d' % frame3)
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_v4_face(Fv_mp4, par): # output mp4 filename Fclrm = 'color2_mm.mp4' # decompose video into bands Fb1 = "b1" # blue Fb2 = "b2" # green Fb3 = "b3" # red Flow([Fb1, Fb2, Fb3], 'video2rsf.x', './video2rsf.x ' + Fv_mp4 + ''' verb=n band1=${TARGETS[0]} band2=${TARGETS[1]} band3=${TARGETS[2]} norm=y ''') # window for now Fb1w = Fb1 + '_w' Fb2w = Fb2 + '_w' Fb3w = Fb3 + '_w' par['ox'] = par['wox'] par['oz'] = par['woz'] par['ot'] = par['wot'] par['nx'] = par['wnx'] par['nz'] = par['wnz'] par['nt'] = par['wnt'] par['dt'] = par['dt'] * par['wjt'] par['ux'] = 'pixels' par['uz'] = 'pixels' par['ut'] = 's' wplot.param(par) Flow( Fb1w, Fb1, 'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d' % par) Flow( Fb2w, Fb2, 'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d' % par) Flow( Fb3w, Fb3, 'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d' % par) # save results for level 0 # pyr.plot_level_cube(Fb1w,par,'gainpanel=a',' label1=z label2=x title="blue band"') #pyr.plot_level_cube(Fb2w,par,'gainpanel=a',' label1=z label2=x title="green band"') #pyr.plot_level_cube(Fb3w,par,'gainpanel=a',' label1=z label2=x title="red band"') frame1 = par['nx'] / 2.0 frame2 = par['nz'] / 2.0 frame3 = par['ot'] Result( Fb1w, ' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="blue band" frame1=%d ' % frame1 + ' frame2=%d ' % frame2 + ' frame3=%d' % frame3) Result( Fb2w, ' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="green band" frame1=%d ' % frame1 + ' frame2=%d ' % frame2 + ' frame3=%d' % frame3) Result( Fb3w, ' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="red band" frame1=%d ' % frame1 + ' frame2=%d ' % frame2 + ' frame3=%d' % frame3) # save accumulation plots Fb1wa = Fb1w + '_acc' Fb2wa = Fb2w + '_acc' Fb3wa = Fb3w + '_acc' pyr.accumulate(Fb1wa, Fb1w, par) pyr.accumulate(Fb2wa, Fb2w, par) pyr.accumulate(Fb3wa, Fb3w, par) # set 'em up par['fs_Hz'] = 1.0 / par['dt'] # perform motion magnification on various videos here Fb1m = Fb1w + '_mm' Fb2m = Fb2w + '_mm' Fb3m = Fb3w + '_mm' pyr.motionmag(Fb1m, Fb1w, par) pyr.motionmag(Fb2m, Fb2w, par) pyr.motionmag(Fb3m, Fb3w, par) pyr.plot_level_cube( Fb1m, par, '', ' label1=z label2=x title="blue band: motion magnified (all levels)"') pyr.plot_level_cube( Fb2m, par, '', ' label1=z label2=x title="green band: motion magnified (all levels)"' ) pyr.plot_level_cube( Fb3m, par, '', ' label1=z label2=x title="red band: motion magnified (all levels)"') Fb1wpm = 'b1_wpm' Fb2wpm = 'b2_wpm' Fb3wpm = 'b3_wpm' Flow(Fb1wpm, [Fb1w, Fb1m], 'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') Flow(Fb2wpm, [Fb2w, Fb2m], 'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') Flow(Fb3wpm, [Fb3w, Fb3m], 'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') # convert motion magnified bands to a video Flow( Fclrm, [Fb1wpm, Fb2wpm, Fb3wpm, 'rsf2video.x'], './rsf2video.x ' + Fv_mp4 + ''' verb=n mp4_out=${TARGETS[0]} band1=${SOURCES[0]} band2=${SOURCES[1]} band3=${SOURCES[2]} fps=30 ''') # custom plot saves for IP project # stacked trace and spectra for raw video # concatenate and normalize before plotting for scale Fb1s = 'b1_w_l00_s' Fb2s = 'b2_w_l00_s' Fb3s = 'b3_w_l00_s' Fb1f = 'b1_w_l00_s_f' Fb2f = 'b2_w_l00_s_f' Fb3f = 'b3_w_l00_s_f' FbAs = 'ba_w_l00_s' FbAf = 'ba_w_l00_s_f' Flow(FbAs, [Fb1s, Fb2s, Fb3s], 'cat axis=2 space=n ${SOURCES[1:3]} | scale axis=123') Flow(FbAf, [Fb1f, Fb2f, Fb3f], 'cat axis=2 space=n ${SOURCES[1:3]} | cabs | scale axis=123') # time series Plot(Fb1s, FbAs, 'window n2=1 f2=0 | graph min2=0 max2=+1.1 title=' ' plotfat=3 plotcol=6') #blue Plot(Fb2s, FbAs, 'window n2=1 f2=1 | graph min2=0 max2=+1.1 title=' ' plotfat=3 plotcol=3') #green Plot(Fb3s, FbAs, 'window n2=1 f2=2 | graph min2=0 max2=+1.1 title=' ' plotfat=3 plotcol=5') #red # spectra Plot(Fb1f, FbAf, 'window n2=1 f2=0 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=6') #blue Plot(Fb2f, FbAf, 'window n2=1 f2=1 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=3') #green Plot(Fb3f, FbAf, 'window n2=1 f2=2 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=5') #red Result(FbAs, [Fb1s, Fb2s, Fb3s], 'Overlay') Result(FbAf, [Fb1f, Fb2f, Fb3f], 'Overlay') # each level motion magnified (cube + trace + frequency plot) for i in range(0, 5): tag = "%02d" % i tagc = "_rui" + '_' + tag tags = "_l" + tag + '_bs_s' tagf = tags + "_f" tagsp = tagf + "_sp" Fcube1 = Fb1m + tagc #cube view Fcube2 = Fb2m + tagc #cube view Fcube3 = Fb3m + tagc #cube view Fcube1s = Fcube1 + '_scaled' #cube view scaled 0-1 Fcube2s = Fcube2 + '_scaled' #cube view scaled 0-1 Fcube3s = Fcube3 + '_scaled' #cube view scaled 0-1 Fb1s = Fb1w + tags #stacked trace Fb2s = Fb2w + tags #stacked trace Fb3s = Fb3w + tags #stacked trace Fb1f = Fb1w + tagf #stacked trace spectra Fb2f = Fb2w + tagf #stacked trace spectra Fb3f = Fb3w + tagf #stacked trace spectra Fb1sp = Fb1w + tagsp #stacked trace spectrogram Fb2sp = Fb2w + tagsp #stacked trace spectrogram Fb3sp = Fb3w + tagsp #stacked trace spectrogram FbAs = 'ba' + tags #stacked trace FbAf = 'ba' + tagf #stacked trace spectra Fmp4 = 'ba' + tagc + '.mp4' #mp4 file print FbAs print FbAf # plot cubes pyr.plot_level_cube( Fcube1, par, '', ''' label1=z label2=x title="blue band: motion magnified (level %d)" ''' % (i)) pyr.plot_level_cube( Fcube2, par, '', ''' label1=z label2=x title="green band: motion magnified (level %d)" ''' % (i)) pyr.plot_level_cube( Fcube3, par, '', ''' label1=z label2=x title="red band: motion magnified (level %d)" ''' % (i)) # write out this level's bands as an MP4 file # scale all bands to be between zero and one Flow(Fcube1s, Fcube1, ' scale axis=123 | math output=input+1 | scale axis=123') Flow(Fcube2s, Fcube2, ' scale axis=123 | math output=input+1 | scale axis=123') Flow(Fcube3s, Fcube3, ' scale axis=123 | math output=input+1 | scale axis=123') Flow( Fmp4, [Fcube1s, Fcube2s, Fcube3s, 'rsf2video.x'], './rsf2video.x ' + Fv_mp4 + ''' verb=n mp4_out=${TARGETS[0]} band1=${SOURCES[0]} band2=${SOURCES[1]} band3=${SOURCES[2]} fps=30 ''') # concatenate and normalize before plotting for scale Flow(FbAs, [Fb1s, Fb2s, Fb3s], 'cat axis=2 space=n ${SOURCES[1:3]} | scale axis=123') Flow(FbAf, [Fb1f, Fb2f, Fb3f], 'cat axis=2 space=n ${SOURCES[1:3]} | cabs | scale axis=123') # time series Plot(Fb1s, FbAs, 'window n2=1 f2=0 | graph min2=-1.1 max2=+1.1 title=' ' plotfat=3 plotcol=6') #blue Plot(Fb2s, FbAs, 'window n2=1 f2=1 | graph min2=-1.1 max2=+1.1 title=' ' plotfat=3 plotcol=3') #green Plot(Fb3s, FbAs, 'window n2=1 f2=2 | graph min2=-1.1 max2=+1.1 title=' ' plotfat=3 plotcol=5') #red # spectra Plot(Fb1f, FbAf, 'window n2=1 f2=0 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=6') #blue Plot(Fb2f, FbAf, 'window n2=1 f2=1 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=3') #green Plot(Fb3f, FbAf, 'window n2=1 f2=2 | graph min2=0 max2=1.1 min1=0 max1=3 title=' ' plotfat=3 plotcol=5') #red Result(FbAs, [Fb1s, Fb2s, Fb3s], 'Overlay') Result(FbAf, [Fb1f, Fb2f, Fb3f], 'Overlay') # save spectra Result(Fb1sp, Fb1s, 'ltft | cabs | grey mean=y color=j title=' ' allpos=y') Result(Fb2sp, Fb2s, 'ltft | cabs | grey mean=y color=j title=' ' allpos=y') Result(Fb3sp, Fb3s, 'ltft | cabs | grey mean=y color=j title=' ' allpos=y')
def motionmag_v4_face(Fv_mp4,par): # output mp4 filename Fclrm='color2_mm.mp4' # decompose video into bands Fb1 ="b1" # blue Fb2 ="b2" # green Fb3 ="b3" # red Flow([Fb1,Fb2,Fb3],'video2rsf.x','./video2rsf.x '+Fv_mp4+ ''' verb=n band1=${TARGETS[0]} band2=${TARGETS[1]} band3=${TARGETS[2]} norm=y ''') # window for now Fb1w=Fb1+'_w' Fb2w=Fb2+'_w' Fb3w=Fb3+'_w' par['ox']=par['wox'] par['oz']=par['woz'] par['ot']=par['wot'] par['nx']=par['wnx'] par['nz']=par['wnz'] par['nt']=par['wnt'] par['dt']=par['dt']*par['wjt'] par['ux']='pixels' par['uz']='pixels' par['ut']='s' wplot.param(par) Flow(Fb1w,Fb1,'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d'%par) Flow(Fb2w,Fb2,'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d'%par) Flow(Fb3w,Fb3,'window n1=%(nz)d n2=%(nx)d n3=%(nt)d f1=%(oz)d f2=%(ox)d f3=%(ot)d j3=%(wjt)d'%par) # save results for level 0 # pyr.plot_level_cube(Fb1w,par,'gainpanel=a',' label1=z label2=x title="blue band"') #pyr.plot_level_cube(Fb2w,par,'gainpanel=a',' label1=z label2=x title="green band"') #pyr.plot_level_cube(Fb3w,par,'gainpanel=a',' label1=z label2=x title="red band"') frame1=par['nx']/2.0 frame2=par['nz']/2.0 frame3=par['ot'] Result(Fb1w,' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="blue band" frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3); Result(Fb2w,' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="green band" frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3); Result(Fb3w,' byte pclip=100 scalebar=y gainpanel=a bar=bar.rsf | grey3 scalebar=y bar=bar.rsf label1=z label2=x title="red band" frame1=%d '%frame1 + ' frame2=%d '%frame2 + ' frame3=%d'%frame3); # save accumulation plots Fb1wa=Fb1w+'_acc' Fb2wa=Fb2w+'_acc' Fb3wa=Fb3w+'_acc' pyr.accumulate(Fb1wa,Fb1w,par) pyr.accumulate(Fb2wa,Fb2w,par) pyr.accumulate(Fb3wa,Fb3w,par) # set 'em up par['fs_Hz'] =1.0/par['dt'] # perform motion magnification on various videos here Fb1m =Fb1w+'_mm' Fb2m =Fb2w+'_mm' Fb3m =Fb3w+'_mm' pyr.motionmag(Fb1m,Fb1w,par) pyr.motionmag(Fb2m,Fb2w,par) pyr.motionmag(Fb3m,Fb3w,par) pyr.plot_level_cube(Fb1m,par,'',' label1=z label2=x title="blue band: motion magnified (all levels)"') pyr.plot_level_cube(Fb2m,par,'',' label1=z label2=x title="green band: motion magnified (all levels)"') pyr.plot_level_cube(Fb3m,par,'',' label1=z label2=x title="red band: motion magnified (all levels)"') Fb1wpm='b1_wpm' Fb2wpm='b2_wpm' Fb3wpm='b3_wpm' Flow(Fb1wpm,[Fb1w,Fb1m],'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') Flow(Fb2wpm,[Fb2w,Fb2m],'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') Flow(Fb3wpm,[Fb3w,Fb3m],'math x=${SOURCES[0]} y=${SOURCES[1]} output=x+y') # convert motion magnified bands to a video Flow(Fclrm,[Fb1wpm,Fb2wpm,Fb3wpm,'rsf2video.x'],'./rsf2video.x '+Fv_mp4+ ''' verb=n mp4_out=${TARGETS[0]} band1=${SOURCES[0]} band2=${SOURCES[1]} band3=${SOURCES[2]} fps=30 ''') # custom plot saves for IP project # stacked trace and spectra for raw video # concatenate and normalize before plotting for scale Fb1s='b1_w_l00_s' Fb2s='b2_w_l00_s' Fb3s='b3_w_l00_s' Fb1f='b1_w_l00_s_f' Fb2f='b2_w_l00_s_f' Fb3f='b3_w_l00_s_f' FbAs='ba_w_l00_s' FbAf='ba_w_l00_s_f' Flow(FbAs,[Fb1s,Fb2s,Fb3s],'cat axis=2 space=n ${SOURCES[1:3]} | scale axis=123') Flow(FbAf,[Fb1f,Fb2f,Fb3f],'cat axis=2 space=n ${SOURCES[1:3]} | cabs | scale axis=123') # time series Plot(Fb1s,FbAs,'window n2=1 f2=0 | graph min2=0 max2=+1.1 title='' plotfat=3 plotcol=6') #blue Plot(Fb2s,FbAs,'window n2=1 f2=1 | graph min2=0 max2=+1.1 title='' plotfat=3 plotcol=3') #green Plot(Fb3s,FbAs,'window n2=1 f2=2 | graph min2=0 max2=+1.1 title='' plotfat=3 plotcol=5') #red # spectra Plot(Fb1f,FbAf,'window n2=1 f2=0 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=6') #blue Plot(Fb2f,FbAf,'window n2=1 f2=1 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=3') #green Plot(Fb3f,FbAf,'window n2=1 f2=2 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=5') #red Result(FbAs,[Fb1s,Fb2s,Fb3s],'Overlay') Result(FbAf,[Fb1f,Fb2f,Fb3f],'Overlay') # each level motion magnified (cube + trace + frequency plot) for i in range(0,5): tag = "%02d"%i tagc = "_rui"+'_'+tag tags = "_l"+tag+'_bs_s' tagf = tags+"_f" tagsp= tagf+"_sp" Fcube1 =Fb1m+tagc #cube view Fcube2 =Fb2m+tagc #cube view Fcube3 =Fb3m+tagc #cube view Fcube1s=Fcube1+'_scaled' #cube view scaled 0-1 Fcube2s=Fcube2+'_scaled' #cube view scaled 0-1 Fcube3s=Fcube3+'_scaled' #cube view scaled 0-1 Fb1s =Fb1w+tags #stacked trace Fb2s =Fb2w+tags #stacked trace Fb3s =Fb3w+tags #stacked trace Fb1f =Fb1w+tagf #stacked trace spectra Fb2f =Fb2w+tagf #stacked trace spectra Fb3f =Fb3w+tagf #stacked trace spectra Fb1sp =Fb1w+tagsp #stacked trace spectrogram Fb2sp =Fb2w+tagsp #stacked trace spectrogram Fb3sp =Fb3w+tagsp #stacked trace spectrogram FbAs ='ba'+tags #stacked trace FbAf ='ba'+tagf #stacked trace spectra Fmp4 ='ba'+tagc+'.mp4' #mp4 file print FbAs print FbAf # plot cubes pyr.plot_level_cube(Fcube1,par,'',''' label1=z label2=x title="blue band: motion magnified (level %d)" '''%(i)) pyr.plot_level_cube(Fcube2,par,'',''' label1=z label2=x title="green band: motion magnified (level %d)" '''%(i)) pyr.plot_level_cube(Fcube3,par,'',''' label1=z label2=x title="red band: motion magnified (level %d)" '''%(i)) # write out this level's bands as an MP4 file # scale all bands to be between zero and one Flow(Fcube1s,Fcube1,' scale axis=123 | math output=input+1 | scale axis=123') Flow(Fcube2s,Fcube2,' scale axis=123 | math output=input+1 | scale axis=123') Flow(Fcube3s,Fcube3,' scale axis=123 | math output=input+1 | scale axis=123') Flow(Fmp4,[Fcube1s,Fcube2s,Fcube3s,'rsf2video.x'],'./rsf2video.x '+Fv_mp4+ ''' verb=n mp4_out=${TARGETS[0]} band1=${SOURCES[0]} band2=${SOURCES[1]} band3=${SOURCES[2]} fps=30 ''') # concatenate and normalize before plotting for scale Flow(FbAs,[Fb1s,Fb2s,Fb3s],'cat axis=2 space=n ${SOURCES[1:3]} | scale axis=123') Flow(FbAf,[Fb1f,Fb2f,Fb3f],'cat axis=2 space=n ${SOURCES[1:3]} | cabs | scale axis=123') # time series Plot(Fb1s,FbAs,'window n2=1 f2=0 | graph min2=-1.1 max2=+1.1 title='' plotfat=3 plotcol=6') #blue Plot(Fb2s,FbAs,'window n2=1 f2=1 | graph min2=-1.1 max2=+1.1 title='' plotfat=3 plotcol=3') #green Plot(Fb3s,FbAs,'window n2=1 f2=2 | graph min2=-1.1 max2=+1.1 title='' plotfat=3 plotcol=5') #red # spectra Plot(Fb1f,FbAf,'window n2=1 f2=0 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=6') #blue Plot(Fb2f,FbAf,'window n2=1 f2=1 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=3') #green Plot(Fb3f,FbAf,'window n2=1 f2=2 | graph min2=0 max2=1.1 min1=0 max1=3 title='' plotfat=3 plotcol=5') #red Result(FbAs,[Fb1s,Fb2s,Fb3s],'Overlay') Result(FbAf,[Fb1f,Fb2f,Fb3f],'Overlay') # save spectra Result(Fb1sp,Fb1s,'ltft | cabs | grey mean=y color=j title='' allpos=y') Result(Fb2sp,Fb2s,'ltft | cabs | grey mean=y color=j title='' allpos=y') Result(Fb3sp,Fb3s,'ltft | cabs | grey mean=y color=j title='' allpos=y')
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='' ''')