def displacement_field(stdout, image_dir, adaptive=False): results = [int(line[1:]) for line in stdout.split('\n') if len(line) > 0 and line[0] == '$'] results = [(results[i], Displacements(*results[i+1:i+3])) for i in range(0, len(results), 3)] disp_map = dict(results) im_pair = get_image_pair(image_dir) if not adaptive: num_rows = frame_rows(im_pair.A) num_cols = frame_cols(im_pair.A) V = np.zeros([num_rows, num_cols]) U = np.zeros([num_rows, num_cols]) for frame_row in range(num_rows): for frame_col in range(num_cols): pixel_ndx = get_px_ndx(im_pair.A, frame_row, frame_col) U[frame_row][frame_col] = disp_map[pixel_ndx].u - 4 V[frame_row][frame_col] = disp_map[pixel_ndx].v - 4 X = np.array(range(num_cols)) * window_spacing + frame_size / 2 Y = np.array(range(num_rows)) * window_spacing + frame_size / 2 else: ndxs = np.array(disp_map.keys()) U = np.array([disp_map[k].u for k in disp_map]) - 4 V = np.array([disp_map[k].v for k in disp_map]) - 4 X = ndxs % im_pair.A.size[0] + frame_size / 2 Y = ndxs // im_pair.A.size[0] + frame_size / 2 return X, Y, U, V
tb_proc = subprocess.Popen(['./tb'],stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd='../scemi/sim') im_pair = get_image_pair(image_dir) bspec_im_width = int(subprocess.check_output('cat ../bspec/PIVTypes.bsv | grep "ImageWidth;"', shell=True).split(' ')[1]) if bspec_im_width != im_pair.A.size[0]: print >> sys.stderr, "WARNING: Image width doesn't match parameters used when compling bspec file. Press Enter to continue anyway." raw_input() tb_proc.stdin.write(str(num_trackers) + '\n') for im in im_pair: for pix in im.convert('L').getdata(): tb_proc.stdin.write(str(pix) + '\n') # print pix tb_proc.stdin.write('.\n') print '.' if adaptive: coords = pickle.load(open('adaptive_coords.pck', 'rb')) for i, pixel_ndx in enumerate(coords): tb_proc.stdin.write(str(pixel_ndx) + '\n') else: for frame_row in range(frame_rows(im_pair.A)): for frame_col in range(frame_cols(im_pair.A)): pixel_ndx = get_px_ndx(im_pair.A, frame_row, frame_col) tb_proc.stdin.write(str(pixel_ndx) + '\n') stdout, stderr = tb_proc.communicate('.\n') pickle.dump(stdout, open(os.path.join(image_dir, 'stdout.pck'), 'wb')) parse_and_show(stdout, image_dir, adaptive)