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).
-
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!
- 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.
- Camera & Projection & Coordinate Transforms
- Pose Solver
- Image & Maps
- Mesh
- Rasterization
- Array Utils
- Segment Array Operations
- IO
| Function | Numpy | Pytorch |
|---|---|---|
utils3d.affine_procrustesExtended Procrustes analysis to solve for affine transformation A and translation t such that y_i ~= A x_i + t. |
utils3d.np.affine_procrustes(cov_yx, cov_xx, cov_yy, mean_x, mean_y, lam, niter) |
- |
utils3d.procrustesProcrustes analysis to solve for scale s, rotation R and translation t such that y_i ~= s R x_i + t. |
utils3d.np.procrustes(cov_yx, cov_xx, cov_yy, mean_x, mean_y, niter) |
- |
utils3d.segment_solve_poseSolve for the pose (transformation from p to q) given weighted point correspondences. |
utils3d.np.segment_solve_pose(p, q, w, offsets, mode, lam, niter) |
- |
utils3d.segment_solve_poses_sequentialSegment array mode for solve_poses_sequential. |
utils3d.np.segment_solve_poses_sequential(trajectories, weights, offsets, accum, min_valid_size, mode, lam, niter) |
- |
utils3d.solve_poseSolve for the pose (transformation from p to q) given weighted point correspondences. |
utils3d.np.solve_pose(p, q, w, mode, lam, niter) |
- |
utils3d.solve_poses_sequentialGiven trajectories of points over time, sequentially solve for the poses (transformations from canonical to each frame) of each body at each frame. |
utils3d.np.solve_poses_sequential(trajectories, weights, accum, min_valid_size, mode, lam, niter) |
- |
utils3d.vector_outer |
utils3d.np.vector_outer(x, y) |
- |
| Function | Numpy | Pytorch |
|---|---|---|
utils3d.csr_eliminate_zerosRemove zero elements from a sparse CSR tensor. |
- | utils3d.pt.csr_eliminate_zeros(input) |
utils3d.csr_matrix_from_dense_indicesConvert a regular indices array to a sparse CSR adjacency matrix format |
utils3d.np.csr_matrix_from_dense_indices(indices, n_cols) |
utils3d.pt.csr_matrix_from_dense_indices(indices, n_cols) |
utils3d.groupSplit the data into groups based on the provided labels. |
utils3d.np.group(labels, data) |
utils3d.pt.group(labels, data) |
utils3d.index_reducePut values into the input tensor at the specified indices (like index_put), with reduction support. |
- | utils3d.pt.index_reduce(input, indices, values, reduce, include_self) |
utils3d.index_reduce_In-place put values into the input tensor at the specified indices (like index_put_), with reduction support. |
- | utils3d.pt.index_reduce_(input, indices, values, reduce, include_self) |
utils3d.large_multinomial |
- | utils3d.pt.large_multinomial(weights, num_samples, replacement) |
utils3d.lexsortPerform lexicographical sort on multiple keys. Like numpy.lexsort. |
- | utils3d.pt.lexsort(keys, dim) |
utils3d.lookupLook up query in key like a dictionary. Useful for COO indexing. |
utils3d.np.lookup(key, query) |
utils3d.pt.lookup(key, query) |
utils3d.lookup_getDictionary-like get for arrays |
utils3d.np.lookup_get(key, value, get_key, default_value) |
utils3d.pt.lookup_get(key, value, get_key, default_value) |
utils3d.lookup_setDictionary-like set for arrays. |
utils3d.np.lookup_set(key, value, set_key, set_value, append, inplace) |
utils3d.pt.lookup_set(key, value, set_key, set_value, append, inplace) |
utils3d.masked_maxSimilar to torch.max, but with mask |
- | utils3d.pt.masked_max(input, mask, dim, keepdim) |
utils3d.masked_minSimilar to torch.min, but with mask |
- | utils3d.pt.masked_min(input, mask, dim, keepdim) |
utils3d.max_pool_2d |
utils3d.np.max_pool_2d(x, kernel_size, stride, padding, axis) |
- |
utils3d.poolingCompute the pooling of the input array. |
utils3d.np.pooling(x, kernel_size, stride, padding, axis, mode) |
- |
utils3d.reverse_permutationCompute the reverse of a permutation array. |
utils3d.np.reverse_permutation(perm, axis) |
utils3d.pt.reverse_permutation(perm, dim) |
utils3d.scatter_argmaxScatter src into input at index along dim with min reduction. Return the indices of the winners in src. |
- | utils3d.pt.scatter_argmax(input, dim, index, src, include_self) |
utils3d.scatter_argminScatter src into input at index along dim with min reduction. Return the indices of the winners in src. |
- | utils3d.pt.scatter_argmin(input, dim, index, src, include_self) |
utils3d.sliding_windowGet a sliding window of the input array. Window axis(axes) will be appended as the last dimension(s). |
utils3d.np.sliding_window(x, window_size, stride, dilation, pad_size, pad_mode, pad_value, axis) |
utils3d.pt.sliding_window(x, window_size, stride, dilation, pad_size, pad_mode, pad_value, dim) |
| Function | Numpy | Pytorch |
|---|---|---|
utils3d.group_as_segmentsGroup as segments by labels |
utils3d.np.group_as_segments(labels, data, return_inverse, return_group_ids) |
utils3d.pt.group_as_segments(labels, data, return_inverse, return_group_ids) |
utils3d.segment_argmaxCompute the argmax of each segment in the segmented data. |
utils3d.np.segment_argmax(data, offsets, axis) |
utils3d.pt.segment_argmax(data, offsets, dim) |
utils3d.segment_argminCompute the argmin of each segment in the segmented data. |
utils3d.np.segment_argmin(data, offsets, axis) |
utils3d.pt.segment_argmin(data, offsets, dim) |
utils3d.segment_argsortCompute the argsort indices within each segment. |
- | utils3d.pt.segment_argsort(input, offsets, descending, dim) |
utils3d.segment_chainConcatenate segmented arrays in sequence. The number of segments are summed. |
- | utils3d.pt.segment_chain(segments, axis) |
utils3d.segment_combinationsGenerate all combinations of elements within each segment. Vectorized implementation. |
- | utils3d.pt.segment_combinations(input, offsets, r, with_replacement) |
utils3d.segment_concat(Alias for segment_concatenate). |
utils3d.np.segment_concat(segments, axis) |
utils3d.pt.segment_concat(segments, axis) |
utils3d.segment_concatenateConcatenate segmented arrays within each segment. All numbers of segments remain the same. |
utils3d.np.segment_concatenate(segments, axis) |
utils3d.pt.segment_concatenate(segments, dim) |
utils3d.segment_cumsumCompute the sum of each segment in the segmented data. Workaround supports for dtypes other than float32. |
- | utils3d.pt.segment_cumsum(input, offsets, dim) |
utils3d.segment_medianCompute the median of each segment. |
- | utils3d.pt.segment_median(input, offsets, dim) |
utils3d.segment_multinomialPerform multinomial sampling within each segment. |
- | utils3d.pt.segment_multinomial(weights, offsets, num_samples, eps, replacement) |
utils3d.segment_rollRoll the data within each segment. |
utils3d.np.segment_roll(data, offsets, shift, axis) |
utils3d.pt.segment_roll(data, offsets, shift, dim) |
utils3d.segment_searchsortedPer-segment searchsorted operation implemented with triton. |
- | utils3d.pt.segment_searchsorted(sorted_sequence, offsets, input, segment_ids, side) |
utils3d.segment_sortSort the data within each segment. |
- | utils3d.pt.segment_sort(input, offsets, descending, dim) |
utils3d.segment_sumCompute the sum of each segment in the segmented data. Workaround supports for dtypes other than float32. |
- | utils3d.pt.segment_sum(input, offsets, dim) |
utils3d.segment_takeTake some segments from a segmented array |
utils3d.np.segment_take(data, offsets, taking, axis) |
utils3d.pt.segment_take(data, offsets, taking, dim) |
utils3d.segment_topkSelect the top-k values and indices within each segment. |
- | utils3d.pt.segment_topk(input, offsets, k, largest, dim) |
utils3d.stack_segmentsStack segments into a padded tensor. |
- | utils3d.pt.stack_segments(input, offsets, max_length, padding_value, dim) |
| Function | Numpy | Pytorch |
|---|---|---|
utils3d.read_extrinsics_from_colmapRead extrinsics from colmap images.txt file. |
utils3d.np.read_extrinsics_from_colmap(file) |
- |
utils3d.read_intrinsics_from_colmapRead intrinsics from colmap cameras.txt file. |
utils3d.np.read_intrinsics_from_colmap(file, normalize) |
- |
utils3d.read_objRead wavefront .obj file. |
utils3d.np.read_obj(file, encoding, ignore_unknown) |
- |
utils3d.read_plyRead a PLY file. Supports arbitrary properties, polygonal meshes. Very fast. |
utils3d.np.read_ply(file) |
- |
utils3d.write_extrinsics_as_colmapWrite extrinsics to colmap images.txt file. |
utils3d.np.write_extrinsics_as_colmap(file, extrinsics, image_names, camera_ids) |
- |
utils3d.write_intrinsics_as_colmapWrite intrinsics to colmap cameras.txt file. Currently only support PINHOLE model (no distortion) |
utils3d.np.write_intrinsics_as_colmap(file, intrinsics, width, height, normalized) |
- |
utils3d.write_obj |
utils3d.np.write_obj(file, obj, encoding) |
- |
utils3d.write_plyWrite a PLY file. Supports arbitrary properties, polygonal meshes. |
utils3d.np.write_ply(file, data, format_) |
- |



