def generate_sss_map(height_map, network_path): network = load_network(network_path) rows, cols = height_map.shape sss_gen_map = np.zeros((rows, cols, 3), dtype=np.uint8) interval = 2. height, width = 256, 256 for i in xrange(0, rows - 20, 20): for j in xrange(0, cols - 20, 20): height_patch = height_map[i:i + 20, j:j + 20] height_patch = clip_to_interval(height_patch, interval) height_patch = cv2.resize(height_patch, (width, height), interpolation=cv2.INTER_CUBIC) height_patch = (255. / interval * height_patch).astype(np.uint8) height_image = cv2.applyColorMap(height_patch, cv2.COLORMAP_JET) generated = predict_sidescan(network, height_image) generated = cv2.resize(generated, dsize=(20, 20), interpolation=cv2.INTER_LINEAR) sss_gen_map[i:i + 20, j:j + 20, :] = generated return sss_gen_map.transpose(1, 0, 2)
def gen_callback(self, bathy_window): print "Got gen callback!" generated_window = np.zeros(bathy_window.shape, dtype=np.float32) interval = 2. height, width = 256, 256 for i in range(0, 9): height_patch = bathy_window[:, i*20:(i+1)*20] height_patch = clip_to_interval(height_patch, interval) height_patch_debug = height_patch.copy() height_patch = cv2.resize(height_patch, (width, height), interpolation = cv2.INTER_CUBIC) height_patch = (255./interval*height_patch).astype(np.uint8) height_image = cv2.applyColorMap(height_patch, cv2.COLORMAP_JET) if i < 4: height_image = np.flip(height_image, axis=1) generated = predict_sidescan(self.network, height_image) if i < 4: generated = np.flip(generated, axis=1) generated = cv2.resize(generated, dsize=(20, 20), interpolation=cv2.INTER_LINEAR) generated_window[:, i*20:(i+1)*20] = 1./255.*generated[:, :, 0].astype(np.float32) #generated_window[:, i*20:(i+1)*20] = 1./interval*height_patch_copy return generated_window
def normalize_depth_slices(depth_slices): depth_slices = [ gen_utils.clip_to_interval(d, 2.) / 2. for d in depth_slices ] for d in depth_slices: d[d == 1.] = 0. return depth_slices
def prepare_depth_window(depth_window): depth_window = gen_utils.clip_to_interval(depth_window, 2.)/2. depth_window[depth_window==1.] = 0. b = (depth_window == 0.).astype(np.uint8) kernel = np.ones((3, 3), np.uint8) b = cv2.dilate(b, kernel, iterations=1).astype(bool) depth_window[b] = 0. #depth_window = cv2.resize(np.rot90(depth_window), (256, 256), interpolation=cv2.INTER_LINEAR) depth_window = cv2.resize(np.rot90(depth_window), (256, 256), interpolation=cv2.INTER_NEAREST) depth_window = (255.*np.minimum(np.maximum(depth_window, 0.), 1.)).astype(np.uint8) depth_window = depth_window[:, :, np.newaxis] return depth_window
patch_views = patch_draper.sss_patch_views.read_data(sys.argv[1]) #patch_views.append(patch_views[0]) print "Number of patches before sss filtering: ", len(patch_views) patch_views = filter_sss_coverage(patch_views) print "Number of patches after sss filtering: ", len(patch_views) patch_views = filter_map_coverage(patch_views) print "Number of patches after map filtering: ", len(patch_views) interval = 2. for view in patch_views: view.patch_height = clip_to_interval(view.patch_height, interval) patch_views = filter_map_nans(patch_views) print "Number of patches after map nan filtering: ", len(patch_views) patch_views = filter_map_extremas(patch_views, interval) print "Number of patches after map extremas filtering: ", len(patch_views) #for i in range(0, len(patch_views), 10): # data_vis.plot_patch_views(patch_views[i:i+10]) if not os.path.exists("pix2pix_sonar"): os.makedirs("pix2pix_sonar") os.makedirs(os.path.join("pix2pix_sonar", "8"))