Created
March 13, 2024 05:04
-
-
Save SeungBack/d83f7ed615f4de97f0c7e1121be1d0f7 to your computer and use it in GitHub Desktop.
load_uoaissim_depth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import imageio | |
| import numpy as np | |
| import pyfastnoisesimd as fns # pip install pyfastnoisesimd | |
| import matplotlib.pyplot as plt | |
| def perlin_noise(frequency, width, height): | |
| noise = fns.Noise() | |
| noise.NoiseType = 2 # perlin noise | |
| noise.frequency = frequency | |
| result = noise.genAsGrid(shape=[height, width], start=[0,0]) | |
| return result | |
| def PerlinDistortion(image): | |
| """ | |
| """ | |
| height, width = image.shape | |
| # sample distortion parameters from noise vector | |
| fx = np.random.uniform(0.0001, 0.1) | |
| fy = np.random.uniform(0.0001, 0.1) | |
| fz = np.random.uniform(0.01, 0.1) | |
| wxy = np.random.uniform(0, 10) | |
| wz = np.random.uniform(0, 0.005) | |
| cnd_x = wxy * perlin_noise(fx, width, height) | |
| cnd_y = wxy * perlin_noise(fy, width, height) | |
| cnd_z = wz * perlin_noise(fz, width, height) | |
| cnd_h = np.array(list(range(height))) | |
| cnd_h = np.expand_dims(cnd_h, -1) | |
| cnd_h = np.repeat(cnd_h, width, -1) | |
| cnd_w = np.array(list(range(width))) | |
| cnd_w = np.expand_dims(cnd_w, 0) | |
| cnd_w = np.repeat(cnd_w, height, 0) | |
| noise_cnd_h = np.int16(cnd_h + cnd_x) | |
| noise_cnd_h = np.clip(noise_cnd_h, 0, (height - 1)) | |
| noise_cnd_w = np.int16(cnd_w + cnd_y) | |
| noise_cnd_w = np.clip(noise_cnd_w, 0, (width - 1)) | |
| new_img = image[(noise_cnd_h, noise_cnd_w)] | |
| new_img = new_img = new_img + cnd_z | |
| return new_img.astype(np.float32) | |
| depth_path = '/home/seung/UOAIS-Sim/train/bin/depth/1452.png' | |
| depth_min = 2500 # 0.25m | |
| depth_max = 15000 # 1.5m | |
| depth = imageio.imread(depth_path).astype(np.float32) | |
| # augmentation for training | |
| depth = PerlinDistortion(depth) | |
| depth[depth > depth_max] = depth_max | |
| depth[depth < depth_min] = depth_min | |
| depth = (depth - depth_min) / (depth_max - depth_min) * 255 | |
| depth = np.expand_dims(depth, -1) # (480, 640, 1), 0~255 --> 네트워크에 넣을 때 255로 다시 나눠줘야함 | |
| plt.imshow(depth, cmap='gray') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment