Utils3d
A collection of useful functions for 3D vision & graphics research in Python.
Install / Use
/learn @EasternJournalist/Utils3dREADME
utils3d
<img src="doc/teaser.jpg" width="100%">A pure-Python collection of useful functions for 3D computer vision and graphics research.
- NumPy / PyTorch pairs: most functions have both implementations.
- Flat & non-modular: standalone functions only, no classes, no hierarchies.
- Native types: always use native Python / NumPy / PyTorch types.
- Vectorized only: no Python loops beyond O(log N).
Install
⚠️ This repo changes quickly. Functions may be added, removed, or modified at any time.
-
If you are looking for one or two specific functions, feel free to copy them directly from the source code. This repo may serve a better purpose as a reference implementation.
-
If installing
utils3das a dependency, use commit id or fork one if you need stability.pip install git+https://github.com/EasternJournalist/utils3d.git@<commit_id> -
If you are willing to accept the latest changes, fork this repo and join me in making 3D research easier!
Documentation
- Use
utils3d.{function}to call the function automatically selecting the backend based on the input type (Numpy ndarray or Pytorch tensor). - Use
utils3d.{np/pt}.{function}to specifically call the Numpy or Pytorch version.
The links below will take you to the source code of each function with detailed documentation and type hints.
Contents
- Camera & Projection & Coordinate Transforms
- Pose Solver
- Image & Maps
- Mesh
- Rasterization
- Array Utils
- Segment Array Operations
- IO
Camera & Projection & Coordinate Transforms
| Function | Numpy | Pytorch |
| ---- | ---- | ---- |
| utils3d.angle_between<br>Calculate the angle between two (batches of) vectors. | utils3d.np.angle_between(v1, v2) | utils3d.pt.angle_between(v1, v2, eps) |
| utils3d.axis_angle_to_matrix<br>Convert axis-angle representation (rotation vector) to rotation matrix, whose direction is the axis of rotation and length is the angle of rotation | utils3d.np.axis_angle_to_matrix(axis_angle) | utils3d.pt.axis_angle_to_matrix(axis_angle, eps) |
| utils3d.axis_angle_to_quaternion<br>Convert axis-angle representation (rotation vector) to quaternion (w, x, y, z) | utils3d.np.axis_angle_to_quaternion(axis_angle) | utils3d.pt.axis_angle_to_quaternion(axis_angle, eps) |
| utils3d.crop_intrinsics<br>Evaluate the new intrinsics after cropping the image | utils3d.np.crop_intrinsics(intrinsics, size, cropped_top, cropped_left, cropped_height, cropped_width) | utils3d.pt.crop_intrinsics(intrinsics, size, cropped_top, cropped_left, cropped_height, cropped_width) |
| utils3d.denormalize_intrinsics<br>Denormalize intrinsics from uv cooridnates to pixel coordinates | utils3d.np.denormalize_intrinsics(intrinsics, size, pixel_convention) | utils3d.pt.denormalize_intrinsics(intrinsics, size, pixel_convention) |
| utils3d.depth_buffer_to_linear<br>OpenGL depth buffer to linear depth | utils3d.np.depth_buffer_to_linear(depth_buffer, near, far) | utils3d.pt.depth_buffer_to_linear(depth, near, far) |
| utils3d.depth_linear_to_buffer<br>Project linear depth to depth value in screen space | utils3d.np.depth_linear_to_buffer(depth, near, far) | utils3d.pt.depth_linear_to_buffer(depth, near, far) |
| utils3d.euler_angles_to_matrix<br>Convert rotations given as Euler angles in radians to rotation matrices. | utils3d.np.euler_angles_to_matrix(euler_angles, convention) | utils3d.pt.euler_angles_to_matrix(euler_angles, convention) |
| utils3d.euler_axis_angle_rotation<br>Return the rotation matrices for one of the rotations about an axis | utils3d.np.euler_axis_angle_rotation(axis, angle) | utils3d.pt.euler_axis_angle_rotation(axis, angle) |
| utils3d.extrinsics_look_at<br>Get OpenCV extrinsics matrix looking at something | utils3d.np.extrinsics_look_at(eye, look_at, up) | utils3d.pt.extrinsics_look_at(eye, look_at, up) |
| utils3d.extrinsics_to_essential<br>extrinsics matrix [[R, t] [0, 0, 0, 1]] such that x' = R (x - t) to essential matrix such that x' E x = 0 | utils3d.np.extrinsics_to_essential(extrinsics) | utils3d.pt.extrinsics_to_essential(extrinsics) |
| utils3d.extrinsics_to_view<br>OpenCV camera extrinsics to OpenGL view matrix | utils3d.np.extrinsics_to_view(extrinsics) | utils3d.pt.extrinsics_to_view(extrinsics) |
| utils3d.focal_to_fov<br> | utils3d.np.focal_to_fov(focal) | utils3d.pt.focal_to_fov(focal) |
| utils3d.fov_to_focal<br> | utils3d.np.fov_to_focal(fov) | utils3d.pt.fov_to_focal(fov) |
| utils3d.interpolate_se3_matrix<br>Linear interpolation between two SE(3) matrices. | utils3d.np.interpolate_se3_matrix(T1, T2, t) | utils3d.pt.interpolate_se3_matrix(T1, T2, t) |
| utils3d.intrinsics_from_focal_center<br>Get OpenCV intrinsics matrix | utils3d.np.intrinsics_from_focal_center(fx, fy, cx, cy) | utils3d.pt.intrinsics_from_focal_center(fx, fy, cx, cy) |
| utils3d.intrinsics_from_fov<br>Get normalized OpenCV intrinsics matrix from given field of view. | utils3d.np.intrinsics_from_fov(fov_x, fov_y, fov_max, fov_min, cx, cy, aspect_ratio) | utils3d.pt.intrinsics_from_fov(fov_x, fov_y, fov_max, fov_min, cx, cy, aspect_ratio) |
| utils3d.intrinsics_to_fov<br>NOTE: approximate FOV by assuming centered principal point | utils3d.np.intrinsics_to_fov(intrinsics) | utils3d.pt.intrinsics_to_fov(intrinsics) |
| utils3d.intrinsics_to_perspective<br>OpenCV intrinsics to OpenGL perspective matrix | utils3d.np.intrinsics_to_perspective(intrinsics, near, far) | utils3d.pt.intrinsics_to_perspective(intrinsics, near, far) |
| utils3d.lerp<br>Linear interpolation between two vectors. | utils3d.np.lerp(x1, x2, t) | utils3d.pt.lerp(v1, v2, t) |
| utils3d.make_affine_matrix<br>Make an affine transformation matrix from a linear matrix and a translation vector. | utils3d.np.make_affine_matrix(M, t) | utils3d.pt.make_affine_matrix(M, t) |
| utils3d.matrix_to_axis_angle<br>Convert a batch of 3x3 rotation matrices to axis-angle representation (rotation vector) | utils3d.np.matrix_to_axis_angle(rot_mat) | utils3d.pt.matrix_to_axis_angle(rot_mat, eps) |
| utils3d.matrix_to_euler_angles<br>Convert rotations given as rotation matrices to Euler angles in radians. | utils3d.np.matrix_to_euler_angles(matrix, convention) | utils3d.pt.matrix_to_euler_angles(matrix, convention) |
| utils3d.matrix_to_quaternion<br>Convert 3x3 rotation matrix to quaternion (w, x, y, z) | utils3d.np.matrix_to_quaternion(rot_mat) | utils3d.pt.matrix_to_quaternion(rot_mat, eps) |
| utils3d.normalize_intrinsics<br>Normalize intrinsics from pixel cooridnates to uv coordinates | utils3d.np.normalize_intrinsics(intrinsics, size, pixel_convention) | utils3d.pt.normalize_intrinsics(intrinsics, size, pixel_convention) |
| utils3d.perspective_from_fov<br>Get OpenGL perspective matrix from field of view | utils3d.np.perspective_from_fov(fov_x, fov_y, fov_min, fov_max, aspect_ratio, near, far) | utils3d.pt.perspective_from_fov(fov_x, fov_y, fov_min, fov_max, aspect_ratio, near, far) |
| utils3d.perspective_from_window<br>Get OpenGL perspective matrix from the window of z=-1 projection plane | utils3d.np.perspective_from_window(left, right, bottom, top, near, far) | utils3d.pt.perspective_from_window(left, right, bottom, top, near, far) |
| utils3d.perspective_to_intrinsics<br>OpenGL perspective matrix to OpenCV intrinsics | utils3d.np.perspective_to_intrinsics(perspective) | utils3d.pt.perspective_to_intrinsics(perspective) |
| utils3d.perspective_to_near_far<br>Get near and far planes from OpenGL perspective matrix | utils3d.np.perspective_to_near_far(perspective) | - |
| `utils3d.piecewise_interpolate_
