def color_coding(flow, rad_org): max_rad_glo = fl2.compute_maxrad(flow) if abs(rad_org - max_rad_glo) < 1: img_ = fl.flow_to_image(flow) else: img_ = fl2.flow_to_image(flow, rad_org) return img_
def reconstruct(data, maxrad, w=200, h=200): x_data = data[0] y_data = data[1] line = np.arange(0, w) data_com_x = x_data[0] * line.reshape(1, -1)**2 + x_data[1] * line.reshape( 1, -1) + x_data[2] x_mat = np.repeat(data_com_x, h, axis=0) col = np.arange(0, h) data_com_y = y_data[0] * col.reshape(-1, 1)**2 + y_data[1] * col.reshape( -1, 1) + y_data[2] y_mat = np.repeat(data_com_y, w, axis=1) flo_x = x_mat[:, :, np.newaxis] flo_y = y_mat[:, :, np.newaxis] flo_global = np.concatenate((flo_x, flo_y), axis=2) flo_global_color = fl2.flow_to_image(flo_global, maxrad) plt.imshow(flo_global_color) plt.show()
interpolation=cv2.INTER_LINEAR) global_motion = global_motion_estimation(data, w=data_org.shape[1], h=data_org.shape[0]) end = time.time() print('time: ', end - start) epe = fl.flow_error(global_motion[0], global_motion[1], data_org[0], data_org[1]) print('epe: {}'.format(epe)) local_motion = data_org - global_motion local_motion_outlier = local_motion * outlier_set flo_global_color = fl2.flow_to_image(global_motion, maxrad) flo_local_color = fl2.flow_to_image(local_motion, maxrad) local_motion_outlier_rad = np.sqrt(local_motion_outlier[:, :, 0]**2 + local_motion_outlier[:, :, 1]**2) local_motion_outlier_mask = np.where( np.abs(local_motion_outlier_rad) > 1.0, 1, 0) local_motion_outlier[:, :, 0] *= local_motion_outlier_mask local_motion_outlier[:, :, 1] *= local_motion_outlier_mask flo_local_outlier_color = fl2.flow_to_image(local_motion_outlier, maxrad) fl.visualize_flow(data_org) plt.imshow(flo_global_color)