A collection of useful Python utility functions for 3D computer vision and graphics researchers.
NOTE: This repo is frequently updated and never guarantees backward compatibility.
- If using
utils3das a dependency, please use a commit ID or fork this repo.- If you find some functions helpful here, consider copying and pasting the functions to your own code.
Install via pip + git
pip install git+https://github.com/EasternJournalist/utils3d.gitor clone the repo and install
git clone https://github.com/EasternJournalist/utils3d.git
pip install ./utils3d| Function | Numpy | Pytorch |
|---|---|---|
utils3d.bounding_rect_from_mask |
- | utils3d.th.bounding_rect_from_mask(mask) |
utils3d.build_mesh_from_depth_mapGet a mesh by lifting depth map to 3D, while removing depths of large depth difference. |
utils3d.np.build_mesh_from_depth_map(depth, other_maps, intrinsics, extrinsics, atol, rtol, tri) |
utils3d.th.build_mesh_from_depth_map(depth, other_maps, intrinsics, extrinsics, atol, rtol, tri) |
utils3d.build_mesh_from_mapGet a mesh regarding image pixel uv coordinates as vertices and image grid as faces. |
utils3d.np.build_mesh_from_map(maps, mask, tri) |
utils3d.th.build_mesh_from_map(maps, mask, tri) |
utils3d.chessboardget x chessboard image |
utils3d.np.chessboard(height, width, grid_size, color_a, color_b) |
utils3d.th.chessboard(width, height, grid_size, color_a, color_b) |
utils3d.depth_map_aliasingCompute the map that indicates the aliasing of x depth map, identifying pixels which neither close to the maximum nor the minimum of its neighbors. |
utils3d.np.depth_map_aliasing(depth, atol, rtol, kernel_size, mask) |
utils3d.th.depth_map_aliasing(depth, atol, rtol, kernel_size, mask) |
utils3d.depth_map_edgeCompute the edge mask from depth map. The edge is defined as the pixels whose neighbors have large difference in depth. |
utils3d.np.depth_map_edge(depth, atol, rtol, kernel_size, mask) |
utils3d.th.depth_map_edge(depth, atol, rtol, kernel_size, mask) |
utils3d.depth_map_to_normal_mapCalculate normal map from depth map. Value range is [-1, 1]. Normal direction in OpenCV identity camera's coordinate system. |
utils3d.np.depth_map_to_normal_map(depth, intrinsics, mask, edge_threshold) |
utils3d.th.depth_map_to_normal_map(depth, intrinsics, mask) |
utils3d.depth_map_to_point_mapUnproject depth map to 3D points. |
utils3d.np.depth_map_to_point_map(depth, intrinsics, extrinsics) |
utils3d.th.depth_map_to_point_map(depth, intrinsics, extrinsics) |
utils3d.normal_map_edgeCompute the edge mask from normal map. |
utils3d.np.normal_map_edge(normals, tol, kernel_size, mask) |
- |
utils3d.pixel_coord_mapGet image pixel coordinates map, where (0, 0) is the top-left corner of the top-left pixel, and (width, height) is the bottom-right corner of the bottom-right pixel. |
utils3d.np.pixel_coord_map(height, width, left, top, definition, dtype) |
utils3d.th.pixel_coord_map(height, width, left, top, definition, dtype, device) |
utils3d.point_map_to_normal_mapCalculate normal map from point map. Value range is [-1, 1]. |
utils3d.np.point_map_to_normal_map(point, mask, edge_threshold) |
utils3d.th.point_map_to_normal_map(point, mask) |
utils3d.screen_coord_mapGet screen space coordinate map, where (0., 0.) is the bottom-left corner of the image, and (1., 1.) is the top-right corner of the image. |
utils3d.np.screen_coord_map(height, width, left, top, right, bottom, dtype) |
- |
utils3d.uv_mapGet image UV space coordinate map, where (0., 0.) is the top-left corner of the image, and (1., 1.) is the bottom-right corner of the image. |
utils3d.np.uv_map(height, width, left, top, right, bottom, dtype) |
utils3d.th.uv_map(height, width, left, top, right, bottom, dtype, device) |
| Function | Numpy | Pytorch |
|---|---|---|
utils3d.lookupLook up query in key like a dictionary. |
utils3d.np.lookup(key, query, value, default_value) |
utils3d.th.lookup(key, query) |
utils3d.masked_max |
- | utils3d.th.masked_max(input, mask, dim, keepdim) |
utils3d.masked_min |
- | utils3d.th.masked_min(input, mask, dim, keepdim) |
utils3d.max_pool_1d |
utils3d.np.max_pool_1d(x, kernel_size, stride, padding, axis) |
- |
utils3d.max_pool_2d |
utils3d.np.max_pool_2d(x, kernel_size, stride, padding, axis) |
- |
utils3d.max_pool_nd |
utils3d.np.max_pool_nd(x, kernel_size, stride, padding, axis) |
- |
utils3d.sliding_window |
utils3d.np.sliding_window(x, window_size, stride, axis) |
utils3d.th.sliding_window(x, window_size, stride, dim) |