print("Defining Converter ...") header = Header() header.w = pca_data[0].shape[1] # input image width header.h = pca_data[0].shape[0] # input image height, trimmed header.sf = 4000000 # magic number, sorry! probe = Probe() probe.radius = 10000 # based on '10' in transducer model number probe.numElements = 128 # based on '128' in transducer model number probe.pitch = 185 # based on Ultrasonix C9-5/10 transducer conv = Converter(header, probe) print("Defining region of interest ...") # get mean frame and apply mask mean_frame = pca_data.mean(axis=0) conv_mean = np.flipud(conv.convert(np.flipud(mean_frame))) plt.title("Mean frame, Spkr {:}".format(subject)) plt.imshow(conv_mean, cmap="Greys_r") file_ending_mean = "subj{:}_mean.pdf".format(subject) savepath_mean = os.path.join(root, d, file_ending_mean) plt.savefig(savepath_mean) roi_upper = 600 roi_lower = 300 roi_left = 20 roi_right = 100 # TODO give mask converted shape while True: mask = us.roi(mean_frame, upper=roi_upper, lower=roi_lower,
start_extr = frame_indices[0] end_extr = frame_indices[-1] # extract and convert v.t1 - v.t2 range for idx in range(start_extr, (end_extr)): # extract frame using RawReader unconv_frame = rdr.get_frame(idx) # trim junk pixels off of top trimmed_frame = unconv_frame[junk:, :] if args.flop: trimmed_frame = np.fliplr(trimmed_frame) # convert to fan shape conv_frame = conv.convert(np.flipud(trimmed_frame)) ready_frame = np.flipud(conv_frame) # create frame handle and save to copy dir fh = basename + "." + "{0:05d}".format(idx) + ".bmp" out_img = Image.fromarray(ready_frame) out_img.save(os.path.join(copy_dir, fh)) frame_exp = os.path.join(copy_dir, basename + ".%05d.bmp") print(frame_exp) framerate = 25 # TODO tweak/automatically get out_fh = basename + '.avi' out_path = os.path.join(copy_dir, out_fh) avi_args = [ 'ffmpeg', '-y', '-i', frame_exp, '-framerate', str(framerate), '-vcodec', 'huffyuv', out_path