def fft_save(frames_iter, path_out, size, count=None, kmax=None): if not kmax: # Ignore features of size smaller than 32 pixels # (My avi file has JPEG artifact of size 8 pixels) kmax = size // 32 # These codes are copied from the examples in cddm package #: create window for multiplication... # window = blackman(SHAPE) #: we must create a video of windows for multiplication # window_video = ((window,),)*NFRAMES #: perform the actual multiplication # video = multiply(video_simulator.video, window_video) video = frames_iter #: if the intesity of light source flickers you can normalize each frame to the intensity of the frame # video = normalize_video(video) #: perform rfft2 and crop results, to take only first kimax and first kjmax wavenumbers. fft = rfft2(video, kimax=kmax, kjmax=kmax) #: you can also normalize each frame with respect to the [0,0] component of the fft #: this it therefore equivalent to normalize_video # fft = normalize_fft(fft) #: load in numpy array # fft_array, = asarrays(fft, count) # np.save(fft_array, path_out) # save into disk asmemmaps(path_out, fft, count=count) return { 'kmax': kmax }
#obtain frames iterator video = fromarrays((vid, )) ##apply blackman window window = blackman(SHAPE) video = apply_window(video, (window, )) #perform rfft2 and crop data video = rfft2(video, kisize=64, kjsize=64) #load all frames into numpy array #video, = asmemmaps("brownian_single_camera_fft", video, nframes) #compute and create numpy array video, = asarrays(video, nframes) np.save("simple_brownian_ddm_fft.npy", video) v1 = np.load("simple_brownian_cddm_video_0.npy") v2 = np.load("simple_brownian_cddm_video_1.npy") nframes = len(v1) #obtain frames iterator video = fromarrays((v1, v2)) ##apply blackman window window = blackman(SHAPE) video = apply_window(video, (window, window)) #perform rfft2 and crop data video = rfft2(video, kisize=64, kjsize=64) #load all frames into numpy array #video, = asmemmaps("brownian_single_camera_fft", video, nframes) #compute and create numpy array asmemmaps("simple_brownian_cddm_fft", video, nframes)
#return ((frame1+frame2,frame1+frame2) for frame1,frame2 in zip(vid1,vid2)) if __name__ == "__main__": print("Computing ddm video...") vid = get_video(seed=0) vid, = video.asarrays(vid, NFRAMES_SINGLE) print("Writing to HD ...") np.save("simple_brownian_ddm_video.npy", vid) print("Computing cddm video...") vid = get_dual_video(seed=0) #we can write directly to HD by creating and writing to numpy memmap v1, v2 = video.asmemmaps("simple_brownian_cddm_video", vid, NFRAMES_DUAL) np.save("simple_brownian_cddm_t1.npy", t1) np.save("simple_brownian_cddm_t2.npy", t2) #print("Writing to HD ...") #np.save("brownian_dual_camera_0.npy",v1) #np.save("brownian_dual_camera_1.npy",v2) #v1 = viewer.VideoViewer(get_dual_video(), n = 1024) #v1.show() v = viewer.VideoViewer(v1) v.show() v = viewer.VideoViewer(v2) v.show()
def test_memmaps(self): video = fromarrays((vid, )) with self.assertRaises(ValueError): video = asmemmaps("deleteme", video) video = asmemmaps("deleteme", video, 128)