| 235 | |
| 236 | # colorize pointcloud using matplotlib colormap |
| 237 | def colormap_pcd(pcd, cmap="viridis", gamma=2.2): |
| 238 | r = np.asarray(pcd.colors)[:, 0] |
| 239 | r_norm = (r - r.min()) / (r.max() - r.min()) |
| 240 | r_corrected = r_norm**(gamma) |
| 241 | colors = matplotlib.colormaps[cmap](r_corrected) # Map the normalized color channel to the color map |
| 242 | if colors.shape[1] == 4: |
| 243 | colors = colors[:, :3] # Remove the alpha channel if present |
| 244 | pcd.colors = o3d.utility.Vector3dVector(colors) |
| 245 | return pcd |
| 246 | |
| 247 | # load point cloud from file (3D: pcd, ply, e57 | 2D: csv, npy), return as pcd object or numpy table |
| 248 | # columns parameter: "XYZ" for 3D, "XZ" for 2D vertical, "I" for intensity or "RGB" for color |