def save_uv_angles(crossfield, base_filepath, name, image_filepath): crossfield = np.transpose(crossfield.numpy(), (1, 2, 0)) u, v = math_utils.compute_crossfield_uv( crossfield) # u, v are complex arrays u_angle, v_angle = np.angle(u), np.angle(v) u_angle, v_angle = np.mod(u_angle, np.pi), np.mod(v_angle, np.pi) uv_angles = np.stack([u_angle, v_angle], axis=-1) uv_angles_as_image = np.round(uv_angles * 255 / np.pi).astype(np.uint8) save_filepath = get_save_filepath(base_filepath, name, ".tif") geo_utils.save_image_as_geotiff(save_filepath, uv_angles_as_image, image_filepath)
def save_seg_luxcarta_format(seg, base_filepath, name, image_filepath): seg = np.transpose(seg.numpy(), (1, 2, 0)) seg_luxcarta = np.zeros((seg.shape[0], seg.shape[1], 1), dtype=np.uint8) seg_interior = 0.5 < seg[..., 0] seg_luxcarta[seg_interior] = 1 if 2 <= seg.shape[2]: seg_edge = 0.5 < seg[..., 1] seg_luxcarta[seg_edge] = 2 seg_luxcarta_filepath = get_save_filepath(base_filepath, name, ".tif") geo_utils.save_image_as_geotiff(seg_luxcarta_filepath, seg_luxcarta, image_filepath)
def save_seg(seg, base_filepath, name, image_filepath): seg = np.transpose(seg.numpy(), (1, 2, 0)) # seg = torch_utils.to_numpy_image(seg) seg_display = plot_utils.get_seg_display(seg) if seg_display.dtype != np.uint8: seg_display = (255 * seg_display).astype(np.uint8) seg_display_filepath = get_save_filepath(base_filepath, name, ".tif") # with warnings.catch_warnings(): # warnings.simplefilter("ignore") # skimage.io.imsave(seg_display_filepath, seg_display) geo_utils.save_image_as_geotiff(seg_display_filepath, seg_display, image_filepath)
def save_seg_mask(seg_mask, base_filepath, name, image_filepath): seg_mask = seg_mask.numpy() out = (255 * seg_mask).astype(np.uint8)[:, :, None] out_filepath = get_save_filepath(base_filepath, name, ".tif") geo_utils.save_image_as_geotiff(out_filepath, out, image_filepath)
def save_seg_mask(seg_mask, base_filepath, image_filepath): seg_mask = seg_mask.numpy() out = (255 * seg_mask).astype(np.uint8)[:, :, None] out_filepath = base_filepath + ".tif" os.makedirs(os.path.dirname(out_filepath), exist_ok=True) geo_utils.save_image_as_geotiff(out_filepath, out, image_filepath)