Skip to content
EasternJournalistPublic

About

A collection of useful functions for 3D vision & graphics research in Python.

Resources

Stars

294 stars

Watchers

3 watching

Forks

Latest commit

 

History

339 Commits

Folders and files

Repository files navigation

This is a stable fork of utils3d maintained as a dependency for microsoft/MoGe.

utils3d

Image

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 utils3d as 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.

Pose-graph numerical precision

The PyTorch-only pose_graph_optimization and pose_graph_optimization_gnc promote compact edge moments and weights to float64 before graph assembly. Rotation synchronization, scale synchronization and translation solves run in float64, including under autocast; GNC also keeps residuals and reweighting in float64 between iterations. This avoids discarding weak nonzero graph modes through float32 pseudoinverse rank thresholds. Results retain the input cross-covariance's dtype and device. Raw point-map reduction, index dtypes, solver objectives and robust-rejection settings are unchanged.

Run the precision regression checks from the repository root with PYTHONPATH=. python test/test_pose_graph_precision.py.

Harmonic-range Huber PGO

utils3d.pt.pose_graph_optimization_huber (also available through automatic dispatch) provides the harmonic-distance Huber IRLS solver. Like the other PGO implementations it is PyTorch-only; no NumPy PGO backend exists.

moments = utils3d.pt.pose_graph_edge_moments(x, y, q)
Q = moments[-1]
harmonic_ranges = torch.stack((Q / (q / range_source).sum(-1), Q / (q / range_target).sum(-1)), dim=-1)
poses, weights, info = utils3d.pt.pose_graph_optimization_huber(
    num_nodes, edges, *moments, harmonic_ranges=harmonic_ranges,
    mode="similar", threshold=0.3,
)

Use positive, guarded ranges from actual observer origins and the same point weights as the original moments. Only the outer score is normalized by s_ij * H_source * H_target; inner point moments/information remain unchanged. Opposite queries share one Huber weight, clamped below by 1e-3. Defaults are 128 outer updates, weight-change tolerance 1e-4, and ten inner rotation refinement steps. All compact calculations use FP64, preserving input dtype and device at the output boundary. info reports iterations and convergence; nonconvergence emits a RuntimeWarning. This solver does not add graph edges or repair initially disconnected graphs. Pixel weight totals and optional edge priors remain coefficients of the inner solver, not the percentage score.

No per-iteration CPU graph diagnostics or raw point decoding are performed. The ordinary PGO and existing GNC APIs retain their behavior.

Separate robust-scoring moments

pose_graph_edge_moments already returns the total point weight as its sixth tensor, so two calls can supply all statistics needed by a relative RMS score:

inner = utils3d.pt.pose_graph_edge_moments(x, y, q)
scoring = utils3d.pt.pose_graph_edge_moments(x, y, q / range_source / range_target)
poses, weights = utils3d.pt.pose_graph_optimization_gnc(
    num_nodes, edges, *inner, mode="similar", threshold=0.05,
    residual_moments=scoring, residual_scale="geometric_mean",
)

Here ranges are fixed distances to the actual camera origins (include any calibration shifts), with positive, unit-consistent near-zero guards. Both calls must use the same point correspondences and validity mask. The inner PGO always uses inner; only the outer residual uses scoring. If the weight sums are Q=sum(q) and A=sum(q/(range_source*range_target)), the squared outer score is A/Q times the scoring-moment mean squared residual, additionally divided by relative Sim(3) scale in "geometric_mean" mode. The resulting RMS is invariant to source/target exchange of the same correspondences and independent local unit changes; 0.05 means 5%. Omitting both new keywords preserves the previous metric and GNC behavior. This change does not alter the continuation schedule, pair directional weights, or add connectivity safeguards.

No point-count output is needed for this weighted metric: its denominator is Q, not the sample count. Callers may separately retain point counts for diagnostics. The cached moments remain valid while point predictions, weights, calibration shifts and range guards stay fixed.

Point-cloud sampling

Both backends return original point indices, so the same selection can be applied to coordinates, colors, normals, or other attributes:

indices = utils3d.voxel_grid_sampling(points, voxel_size=0.01)
indices = utils3d.hierarchical_voxel_sampling(points, num_samples=100_000)
sampled_points = points[indices]

Inputs are finite floating-point arrays/tensors of shape (N, 3); outputs are one-dimensional int64 indices, on the input device for PyTorch.

  • voxel_grid_sampling keeps the first input point in each occupied cubic voxel. The grid is anchored at the coordinate-wise minimum. Every input point is within sqrt(3) * voxel_size of a selected point, up to numerical rounding.
  • hierarchical_voxel_sampling sorts 21-bit-per-axis Morton codes once, chooses an octree level, and refines a spatially dispersed subset of its cells. Final cells differ by at most one level. Each is represented by the first point in Morton order, with original index breaking ties. For 0 < num_samples < N, if U finest-grid cells are occupied and T = min(num_samples, U), the output count is between max(1, T - 6) and T. Duplicate coordinates or finest-grid quantization can reduce U; outliers can limit effective resolution. A zero target gives empty indices, and a target at least N returns all indices, including coincident points.

These are grid-based coverage samplers, not FPS or Poisson-disk sampling: there is no minimum point-separation guarantee, no progressive FPS ordering, and selections need not be nested across targets. Both use float64 grid arithmetic, O(N) workspace, and sorting (O(N log N) in the comparison model), without loops over input points or output samples. PyTorch selection runs without autograd; gathering the returned indices can still propagate gradients. The PyTorch implementations require a device supporting float64, read bounds and (for the hierarchical sampler) at most five level counts on the CPU, and otherwise keep point data on the input device.

Invalid shapes, dtypes, parameters, nonfinite coordinates, and unrepresentable coordinate ranges raise errors. Single-scale voxel coordinates must fit int64; if only the packed key would overflow, lexicographic sorting preserves distinct voxels instead of allowing collisions.

Run the NumPy / PyTorch CPU and available-CUDA regression checks with PYTHONPATH=. python test/test_sampling.py.

JIT GPU rasterization

utils3d.pt.rasterize_triangles, utils3d.pt.rasterize_lines, and utils3d.pt.rasterize_point_cloud share a small, point-sampled Triton rasterizer. It implements homogeneous view-frustum clipping, backface culling, a top-left shared-edge rule with eight subpixel bits, and perspective-correct interpolation. Unsigned 64-bit atomic depth/face keys select the visible triangle; equal depths choose the lowest face ID. It scans triangle bounding boxes, without a scene graph, binning queues, or cached graphics contexts. Large overlapping or thin triangles can be slow; this is a reference implementation, not a replacement for a full graphics engine.

Install compatible GPU builds of PyTorch and Triton separately (pip install torch triton). No nvdiffrast, OpenGL context, or custom CUDA/C++ extension is needed for the Torch path. NVIDIA execution still requires a GPU driver and the PyTorch/Triton runtime; it does not require compiling .cu sources or configuring a CUDA toolkit. Triton is loaded only when rendering is requested. The NumPy/ModernGL backend is unchanged.

import torch
import utils3d

vertices = torch.tensor([
    [-0.8, -0.8, 0.0], [0.8, -0.8, 0.0], [0.0, 0.8, 0.0],
], device="cuda")
faces = torch.tensor([[0, 1, 2]], device="cuda")
colors = torch.eye(3, device="cuda", requires_grad=True)
result = utils3d.pt.rasterize_triangles(
    (256, 256), vertices=vertices, faces=faces, attributes=colors,
    return_interpolation=True,
)
result["image"].sum().backward()  # Gradients flow to colors, not geometry.

Coordinates and camera matrices are float32 GPU tensors. Faces are shared (T, 3) int32/int64 indices; omit them for (..., T, 3, D) triangle soup. Vertex coordinates may have 2, 3, or 4 components. Vertex, camera and attribute batch dimensions broadcast. Attribute tensors support any number of channels and retain their floating-point dtype. Use attributes_domain="face" for constant per-face attributes.

Outputs follow NumPy's top-left image convention: image has shape (..., H, W, C), and mask has shape (..., H, W). Optional depth is camera-space -z/w, with inf for background; with identity transforms this is simply negative input z. Optional interpolation_id contains original face IDs (-1 for background), and interpolation_uv contains the first two perspective-correct barycentric weights (zero for background). NDC depth uses strict < 1 far-plane testing. Geometry outputs are detached; only attributes receive gradients through native PyTorch indexing and weighted sums. Validation checks finite transformed coordinates and index bounds with one GPU-to-CPU synchronization. Background attributes are zero unless supplied explicitly.

Background images and depth

Triangle, line and point-cloud rendering accept a background dictionary. Compositing uses PyTorch operations after rasterization, without changing the JIT core:

result = utils3d.pt.rasterize_triangles(
    (256, 256), vertices=vertices, faces=faces, attributes=colors,
    background={
        "image": background_image,  # (..., H, W, C), same dtype/channels as colors
        "depth": background_depth,  # (..., H, W), float32 camera-space -z/w
    },
    return_depth=True,
)

Every entry is optional. The image uses the same top-left origin as the outputs. Background depth is linear camera-space depth, not NDC, ray distance or an alpha channel. Finite values (including signed depths for identity transforms) and +inf are accepted; NaN and -inf raise errors. A covered foreground pixel wins only when its depth is strictly smaller; ties retain the background. Without background depth, foreground coverage alone selects the winner. Depth occlusion also works with return_depth=False: depth is computed internally but not returned. Point billboards use their center's camera depth for this test.

Background dictionaries may additionally carry mask (bool), interpolation_id (int32) and interpolation_uv (float32, last dimension 2) for triangles/lines, or point_id (int32) for points. All requested output maps follow the same winner. Missing fields default to zero image/UV, inf depth, -1 ID and false mask, matching NumPy's independent background-mask semantics. Mask is not inferred from an image or finite depth, and a false mask does not disable depth occlusion; supply a mask explicitly if background coverage should be reported. Metadata is returned only when its corresponding return flag is enabled. IDs are preserved without rebasing, so use a consistent ID convention when chaining render passes.

All tensors must share the geometry's GPU; spatial dimensions must match the requested image, while leading batch dimensions broadcast with geometry, cameras and attributes. Background images retain gradients, along with foreground attributes. Depth, selection and metadata remain detached. Inputs are not mutated. Without foreground attributes, a background image still produces an image output, with zero-valued foreground pixels. This is depth-based selection, not alpha blending. Depth peeling retains its separate background-free layer interface.

Points and lines

Point billboards and line rectangles are expanded on the GPU and reuse the triangle coverage/depth core, rather than maintaining separate depth algorithms. Attribute lookup and interpolation remain native PyTorch operations.

point_result = utils3d.pt.rasterize_point_cloud(
    (256, 256), points=vertices, attributes=colors,
    point_sizes=12, point_shape="circle", return_point_id=True,
)
line_result = utils3d.pt.rasterize_lines(
    (256, 256), vertices=vertices, attributes=colors,
    lines=torch.tensor([[0, 1], [1, 2], [2, 0]], device="cuda"),
    line_width=2.5, return_interpolation=True,
)
  • Points: all five NumPy shapes are supported: triangle, square, pentagon, hexagon and circle. Sizes can be a scalar or a broadcasting (..., N) / (..., 1) GPU tensor. point_size_in="2d" uses pixels; "3d" uses camera-plane units, matching NumPy's billboard convention. Square size is its side length; circle size is its diameter; other polygons use the circumcircle diameter. Zero sizes are invisible. The full billboard is clipped, so centers outside the image can still contribute. Circles discard outside fragments before depth testing. Optional point_id stores original IDs with background -1; depth is the point center's camera-space depth.
  • Lines: supply shared (L, 2) indices or unindexed (..., L, 2, D) endpoints. attributes_domain="line" selects constant per-line attributes; the default interpolates endpoint attributes perspective-correctly. Centerlines are clipped against all six frustum planes, then expanded to flat-capped rectangles with the requested perpendicular width in pixels. Widths need not be integers. Projected zero-length lines are invisible. interpolation_id stores original line IDs, while interpolation_uv stores the two original endpoint weights, including after clipping.
  • Coverage is intentionally not bit-identical to OpenGL lines: the Torch implementation uses geometric rectangles, not driver-specific aliased line/diamond-exit rules. Diagonal edges and endpoints may cover different pixels. There is no antialiasing or automatic joining of adjacent segments.

Positions, cameras and point sizes are detached; only attributes receive gradients. The same batching, dtype, background, and optional-dependency rules apply to all three renderers. Expanded primitives require O(N) geometry storage, not an image-by-primitive tensor.

Triangle depth peeling

utils3d.pt.rasterize_triangles_peeling returns a context-managed layer iterator. It accepts the same geometry, camera, attribute-domain and output options as triangle rendering, without a graphics context:

with utils3d.pt.rasterize_triangles_peeling(
    (256, 256), vertices=vertices, faces=faces, attributes=colors,
    return_depth=True, return_interpolation=True,
) as layers:
    for i, layer in enumerate(layers):
        image = layer["image"]  # (..., H, W, C), including the final empty layer.
        if i == 3:
            break

The first layer matches ordinary rendering. Each next layer selects the closest fragment at strictly greater float32 NDC depth per pixel. Equal-depth fragments are skipped together; face ID breaks ties within a layer. Exhausted pixels stay empty, and iteration ends after yielding one entirely empty layer across the batch. Geometry is prepared once, then rerasterized per layer, with one CPU coverage check per layer. There is no fixed layer limit; leaving the with block closes the iterator. Outputs can be retained, and attribute losses can be summed over layers before backward. Do not mutate inputs while iterating.

Migration from the nvdiffrast wrapper: the Torch RastContext, sample_texture, and texture_composite APIs have been removed, as have the ctx, antialiasing, and return_image_derivatives rendering parameters. There is no geometry gradient, screen-space derivative, mipmap or antialiasing path. Texture sampling can be composed separately with PyTorch operations. Background image/depth compositing is supported as described above. Triangle peeling is now available through the Triton layer iterator above. NumPy-only functions remain available through utils3d.np and automatic dispatch.

Run the GPU, independent CPU-reference, optional NumPy/OpenGL, attribute-gradient and lazy-import regression checks with PYTHONPATH=. python test/test_rasterization.py.

Contents

Camera & Projection & Coordinate Transforms

Function Numpy Pytorch
utils3d.angle_between
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
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
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
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
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
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
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
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
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
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
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
OpenCV camera extrinsics to OpenGL view matrix
utils3d.np.extrinsics_to_view(extrinsics) utils3d.pt.extrinsics_to_view(extrinsics)
utils3d.focal_to_fov
utils3d.np.focal_to_fov(focal) utils3d.pt.focal_to_fov(focal)
utils3d.fov_to_focal
utils3d.np.fov_to_focal(fov) utils3d.pt.fov_to_focal(fov)
utils3d.interpolate_se3_matrix
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
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
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
NOTE: approximate FOV by assuming centered principal point
utils3d.np.intrinsics_to_fov(intrinsics) utils3d.pt.intrinsics_to_fov(intrinsics)
utils3d.intrinsics_to_perspective
OpenCV intrinsics to OpenGL perspective matrix
utils3d.np.intrinsics_to_perspective(intrinsics, near, far) utils3d.pt.intrinsics_to_perspective(intrinsics, near, far)
utils3d.lerp
Linear interpolation between two vectors.
utils3d.np.lerp(x1, x2, t) utils3d.pt.lerp(v1, v2, t)
utils3d.make_affine_matrix
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
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
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
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
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
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
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
OpenGL perspective matrix to OpenCV intrinsics
utils3d.np.perspective_to_intrinsics(perspective) utils3d.pt.perspective_to_intrinsics(perspective)
utils3d.perspective_to_near_far
Get near and far planes from OpenGL perspective matrix
utils3d.np.perspective_to_near_far(perspective) -
utils3d.piecewise_interpolate_se3_matrix
Linear spline interpolation for SE(3) matrices.
utils3d.np.piecewise_interpolate_se3_matrix(T, t, s, extrapolation_mode) -
utils3d.piecewise_lerp
Linear spline interpolation.
utils3d.np.piecewise_lerp(x, t, s, extrapolation_mode) -
utils3d.pixel_to_ndc
Convert pixel coordinates to NDC (Normalized Device Coordinates).
utils3d.np.pixel_to_ndc(pixel, size, pixel_convention) utils3d.pt.pixel_to_ndc(pixel, size, pixel_convention)
utils3d.pixel_to_uv
Convert pixel space coordiantes to UV space coordinates.
utils3d.np.pixel_to_uv(pixel, size, pixel_convention) utils3d.pt.pixel_to_uv(pixel, size, pixel_convention)
utils3d.project
Calculate projection.
utils3d.np.project(points, intrinsics, extrinsics, view, projection) utils3d.pt.project(points, intrinsics, extrinsics, view, projection)
utils3d.project_cv
Project 3D points to 2D following the OpenCV convention
utils3d.np.project_cv(points, intrinsics, extrinsics) utils3d.pt.project_cv(points, intrinsics, extrinsics)
utils3d.project_gl
Project 3D points to 2D following the OpenGL convention (except for row major matrices)
utils3d.np.project_gl(points, projection, view) utils3d.pt.project_gl(points, projection, view)
utils3d.quaternion_inverse
Calculate the inverse of a batch of quaternions (w, x, y, z)
utils3d.np.quaternion_inverse(quaternion) utils3d.pt.quaternion_inverse(quaternion)
utils3d.quaternion_multiply
Multiplies two quaternions (w, x, y, z)
utils3d.np.quaternion_multiply(q1, q2) utils3d.pt.quaternion_multiply(q1, q2)
utils3d.quaternion_normalize
Normalize quaternions (w, x, y, z) to unit length and positive w component
utils3d.np.quaternion_normalize(quaternion) utils3d.pt.quaternion_normalize(quaternion, eps)
utils3d.quaternion_to_axis_angle
Convert a batch of quaternions (w, x, y, z) to axis-angle representation (rotation vector)
utils3d.np.quaternion_to_axis_angle(quaternion) utils3d.pt.quaternion_to_axis_angle(quaternion, eps)
utils3d.quaternion_to_matrix
Converts a batch of quaternions (w, x, y, z) to rotation matrices
utils3d.np.quaternion_to_matrix(quaternion) utils3d.pt.quaternion_to_matrix(quaternion, eps)
utils3d.random_rotation_matrix
Generate random 3D rotation matrix.
utils3d.np.random_rotation_matrix(size, dtype) utils3d.pt.random_rotation_matrix(size, dtype, device)
utils3d.ray_intersection
Compute the intersection/closest point of two D-dimensional rays
utils3d.np.ray_intersection(p1, d1, p2, d2) -
utils3d.rotate_2d
3x3 matrix for 2D rotation around a center
- utils3d.pt.rotate_2d(theta, center)
utils3d.rotation_matrix_2d
2x2 matrix for 2D rotation
- utils3d.pt.rotation_matrix_2d(theta)
utils3d.rotation_matrix_from_vectors
Rotation matrix that rotates v1 to v2
utils3d.np.rotation_matrix_from_vectors(v1, v2) utils3d.pt.rotation_matrix_from_vectors(v1, v2)
utils3d.scale_2d
Scale matrix for 2D scaling
- utils3d.pt.scale_2d(scale, center)
utils3d.screen_coord_to_view_coord
Unproject screen space coordinates to 3D view space following the OpenGL convention (except for row major matrices)
utils3d.np.screen_coord_to_view_coord(screen_coord, projection) -
utils3d.skew_symmetric
Skew symmetric matrix from a 3D vector
utils3d.np.skew_symmetric(v) utils3d.pt.skew_symmetric(v)
utils3d.slerp
Spherical linear interpolation between two (unit) vectors.
utils3d.np.slerp(v1, v2, t) utils3d.pt.slerp(v1, v2, t, eps)
utils3d.slerp_rotation_matrix
Spherical linear interpolation between two rotation matrices.
utils3d.np.slerp_rotation_matrix(R1, R2, t) utils3d.pt.slerp_rotation_matrix(R1, R2, t)
utils3d.transform_points
Apply transformation(s) to a point or a set of points.
utils3d.np.transform_points(x, Ts) utils3d.pt.transform_points(x, Ts)
utils3d.translate_2d
Translation matrix for 2D translation
- utils3d.pt.translate_2d(translation)
utils3d.unproject
Calculate inverse projection.
utils3d.np.unproject(uv, depth, intrinsics, extrinsics, projection, view) utils3d.pt.unproject(uv, depth, intrinsics, extrinsics, projection, view)
utils3d.unproject_cv
Unproject uv coordinates to 3D view space following the OpenCV convention
utils3d.np.unproject_cv(uv, depth, intrinsics, extrinsics) utils3d.pt.unproject_cv(uv, depth, intrinsics, extrinsics)
utils3d.unproject_gl
Unproject screen space coordinates to 3D view space following the OpenGL convention (except for row major matrices)
utils3d.np.unproject_gl(uv, depth, projection, view) utils3d.pt.unproject_gl(uv, depth, projection, view)
utils3d.uv_to_pixel
Convert UV space coordinates to pixel space coordinates.
utils3d.np.uv_to_pixel(uv, size, pixel_convention) utils3d.pt.uv_to_pixel(uv, size, pixel_convention)
utils3d.view_look_at
Get OpenGL view matrix looking at something
utils3d.np.view_look_at(eye, look_at, up) utils3d.pt.view_look_at(eye, look_at, up)
utils3d.view_to_extrinsics
OpenGL view matrix to OpenCV camera extrinsics
utils3d.np.view_to_extrinsics(view) utils3d.pt.view_to_extrinsics(view)

Pose Solver

Function Numpy Pytorch
utils3d.affine_umeyama
Extended Procrustes analysis to solve for affine transformation A and translation t such that y_i ~= A x_i + t.
utils3d.np.affine_umeyama(cov_yx, cov_xx, cov_yy, mean_x, mean_y, lam, allow_flip) utils3d.pt.affine_umeyama(cov_yx, cov_xx, cov_yy, mean_x, mean_y, lam, eps, allow_flip)
utils3d.kabsch
Backward gradients friendly Kabsch method (compute rotation from input covarience matrix).
utils3d.np.kabsch(cov) utils3d.pt.kabsch(cov, eps)
utils3d.pose_graph_edge_moments
Reduce per-edge point correspondences to centered second-moment statistics for pose graph optimization.
- utils3d.pt.pose_graph_edge_moments(x, y, w, eps)
utils3d.pose_graph_optimization
Pose graph optimization for global poses from per-edge centered point statistics.
- utils3d.pt.pose_graph_optimization(num_nodes, edges, cov_yx, cov_xx, cov_yy, mean_x, mean_y, w, edge_weights, mode, niter, eps)
utils3d.pose_graph_optimization_gnc
Robust pose graph optimization with Graduated Non-Convexity (GNC-TLS) for outlier edge rejection.
- utils3d.pt.pose_graph_optimization_gnc(num_nodes, edges, cov_yx, cov_xx, cov_yy, mean_x, mean_y, w, edge_weights, mode, threshold, niter, gnc_iters, gnc_factor, eps, residual_moments, residual_scale)
utils3d.pose_graph_optimization_huber
Reweight pose-graph edges with Huber on harmonic-range-normalized point RMS.
- utils3d.pt.pose_graph_optimization_huber(num_nodes, edges, cov_yx, cov_xx, cov_yy, mean_x, mean_y, w, edge_weights, harmonic_ranges, mode, threshold, niter, max_iterations, tolerance, weight_floor)
utils3d.segment_pose_graph_edge_moments
Segment array mode for pose_graph_edge_moments.
- utils3d.pt.segment_pose_graph_edge_moments(x, y, w, offsets, eps)
utils3d.segment_solve_pose
Solve for the pose (transformation from p to q) given weighted point correspondences.
utils3d.np.segment_solve_pose(p, q, w, sigma, offsets, mode, lam) utils3d.pt.segment_solve_pose(p, q, w, sigma, offsets, mode, lam, eps)
utils3d.segment_solve_poses_sequential
Segment array mode for solve_poses_sequential.
utils3d.np.segment_solve_poses_sequential(trajectories, weights, offsets, noise_scales, accum, min_valid_size, mode, lam) utils3d.pt.segment_solve_poses_sequential(trajectories, weights, offsets, noise_scales, accum, min_valid_size, mode, lam, eps)
utils3d.solve_pose
Solve for the pose (transformation from p to q) given weighted point correspondences.
utils3d.np.solve_pose(p, q, w, sigma, mode, lam) utils3d.pt.solve_pose(p, q, w, sigma, mode, lam, eps)
utils3d.solve_pose_ransac
Robustly solve for the pose (transformation from p to q) given point correspondences using RANSAC.
utils3d.np.solve_pose_ransac(p, q, w, sigma, mode, threshold, ratio, num_samples, sample_size, lam, rng) utils3d.pt.solve_pose_ransac(p, q, w, sigma, mode, threshold, ratio, num_samples, sample_size, lam, eps, generator)
utils3d.solve_poses_sequential
Given 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, noise_scales, accum, min_valid_size, mode, lam) utils3d.pt.solve_poses_sequential(trajectories, weights, noise_scales, accum, min_valid_size, mode, lam, eps)
utils3d.umeyama
Procrustes analysis to solve for scale s, rotation R and translation t such that y_i ~= s R x_i + t.
utils3d.np.umeyama(cov_yx, cov_xx, cov_yy, mean_x, mean_y) utils3d.pt.umeyama(cov_yx, cov_xx, cov_yy, mean_x, mean_y, eps)

Image & Maps

Function Numpy Pytorch
utils3d.bounding_rect_from_mask
Get bounding rectangle of a mask
- utils3d.pt.bounding_rect_from_mask(mask)
utils3d.build_grid_mesh
Get mesh of height * width faces arranged in a 2D grid.
utils3d.np.build_grid_mesh(height, width, shared_vertices) -
utils3d.build_mesh_from_depth_map
Get a mesh by lifting depth map to 3D, while removing depths of large depth difference.
utils3d.np.build_mesh_from_depth_map(depth, maps, intrinsics, extrinsics, atol, rtol, domain, tri) utils3d.pt.build_mesh_from_depth_map(depth, other_maps, intrinsics, extrinsics, atol, rtol, tri)
utils3d.build_mesh_from_map
Get a mesh regarding image pixel uv coordinates as vertices and image grid as faces.
utils3d.np.build_mesh_from_map(maps, mask, domain, tri) utils3d.pt.build_mesh_from_map(maps, mask, tri)
utils3d.chessboard
Get a chessboard image
utils3d.np.chessboard(size, grid_size, color_a, color_b) utils3d.pt.chessboard(size, grid_size, color_a, color_b)
utils3d.colorize_depth_map
Colorize depth map for visualization.
utils3d.np.colorize_depth_map(depth, mask, near, far, cmap) -
utils3d.colorize_normal_map
Colorize normal map for visualization. Value range is [-1, 1].
utils3d.np.colorize_normal_map(normal, mask, flip_yz, normalize) -
utils3d.colorize_probability_map
Colorize probability map for visualization.
utils3d.np.colorize_probability_map(probability, mask, cmap, alpha, beta) -
utils3d.colorize_segmentation_map
Colorize segmentation map for visualization. The same value will be assigned with the same color.
utils3d.np.colorize_segmentation_map(segmentation, mask, vdim) -
utils3d.depth_map_aliasing
Compute 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.pt.depth_map_aliasing(depth, atol, rtol, kernel_size, mask)
utils3d.depth_map_edge
Compute 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, ltol, kernel_size, mask) utils3d.pt.depth_map_edge(depth, atol, rtol, ltol, kernel_size, mask)
utils3d.depth_map_to_normal_map
Calculate 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.pt.depth_map_to_normal_map(depth, intrinsics, mask)
utils3d.depth_map_to_point_map
Unproject depth map to 3D points.
utils3d.np.depth_map_to_point_map(depth, intrinsics, extrinsics) utils3d.pt.depth_map_to_point_map(depth, intrinsics, extrinsics)
utils3d.flood_fill
Flooding fill the holes in the image(s) according to the mask. doc/flood_fill.png
utils3d.np.flood_fill(image, mask, return_index) utils3d.pt.flood_fill(image, mask, return_index)
utils3d.fractal_perlin_noise_map
Generate fractal Perlin noise map. fractal_perlin_base_frequeny2_octaves7_gain0.7.png
utils3d.np.fractal_perlin_noise_map(size, base_frequency, octaves, lacunarity, gain, seed, dtype) utils3d.pt.fractal_perlin_noise_map(size, base_frequency, octaves, lacunarity, gain, seed, dtype, device)
utils3d.masked_area_resize
Resize 2D map by area sampling with mask awareness.
utils3d.np.masked_area_resize(image, mask, size) utils3d.pt.masked_area_resize(image, mask, size)
utils3d.masked_nearest_resize
Resize image(s) by nearest sampling with mask awareness. Suitable for sparse maps. masked_nearest_resize.png
utils3d.np.masked_nearest_resize(image, mask, size, return_index) utils3d.pt.masked_nearest_resize(image, mask, size, return_index)
utils3d.normal_map_edge
Compute the edge mask from normal map.
utils3d.np.normal_map_edge(normals, tol, kernel_size, mask) -
utils3d.perlin_noise
Generate Perlin noise for the given coordinates.
utils3d.np.perlin_noise(x, seed) utils3d.pt.perlin_noise(x, seed)
utils3d.perlin_noise_map
Generate Perlin noise map.
utils3d.np.perlin_noise_map(size, frequency, seed, dtype) utils3d.pt.perlin_noise_map(size, frequency, seed, dtype, device)
utils3d.pixel_coord_map
Get 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(size, top, left, convention, dtype) utils3d.pt.pixel_coord_map(size, top, left, convention, dtype, device)
utils3d.point_map_to_normal_map
Calculate normal map from point map. Value range is [-1, 1].
utils3d.np.point_map_to_normal_map(point, mask, edge_threshold) utils3d.pt.point_map_to_normal_map(point, mask)
utils3d.screen_coord_map
Get 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(size, top, left, bottom, right, dtype) utils3d.pt.screen_coord_map(size, top, left, bottom, right, dtype, device)
utils3d.uv_map
Get 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(size, top, left, bottom, right, dtype) utils3d.pt.uv_map(size, top, left, bottom, right, dtype, device)

Mesh

Function Numpy Pytorch
utils3d.compute_boundaries
Compute boundary edges of a mesh.
- utils3d.pt.compute_boundaries(faces, edges, face2edge, edge_degrees)
utils3d.compute_face_corner_angles
Compute face corner angles of a mesh
utils3d.np.compute_face_corner_angles(vertices, faces) utils3d.pt.compute_face_corner_angles(vertices, faces)
utils3d.compute_face_corner_normals
Compute the face corner normals of a mesh
utils3d.np.compute_face_corner_normals(vertices, faces, normalize) utils3d.pt.compute_face_corner_normals(vertices, faces, normalize)
utils3d.compute_face_corner_tangents
Compute the face corner tangent (and bitangent) vectors of a mesh
utils3d.np.compute_face_corner_tangents(vertices, uv, faces_vertices, faces_uv, normalize) utils3d.pt.compute_face_corner_tangents(vertices, uv, faces_vertices, faces_uv, normalize)
utils3d.compute_face_normals
Compute face normals of a mesh
utils3d.np.compute_face_normals(vertices, faces) utils3d.pt.compute_face_normals(vertices, faces)
utils3d.compute_face_tangents
Compute the face corner tangent (and bitangent) vectors of a mesh
utils3d.np.compute_face_tangents(vertices, uv, faces_vertices, faces_uv, normalize) utils3d.pt.compute_face_tangents(vertices, uv, faces_vertices, faces_uv, normalize)
utils3d.compute_mesh_laplacian
Laplacian smooth with cotangent weights
- utils3d.pt.compute_mesh_laplacian(vertices, faces, weight)
utils3d.compute_vertex_normals
Compute vertex normals of a triangular mesh by averaging neighboring face normals
utils3d.np.compute_vertex_normals(vertices, faces, weighted) -
utils3d.create_camera_frustum_mesh
Create a triangle mesh of camera frustum.
utils3d.np.create_camera_frustum_mesh(extrinsics, intrinsics, depth) utils3d.pt.create_camera_frustum_mesh(extrinsics, intrinsics, depth)
utils3d.create_cube_mesh
Create a cube mesh of size 1 centered at origin.
utils3d.np.create_cube_mesh(tri) utils3d.pt.create_cube_mesh(tri, device)
utils3d.create_icosahedron_mesh
Create an icosahedron mesh of centered at origin.
utils3d.np.create_icosahedron_mesh() utils3d.pt.create_icosahedron_mesh(device)
utils3d.create_square_mesh
Create a square mesh of area 1 centered at origin in the xy-plane.
utils3d.np.create_square_mesh(tri) -
utils3d.flatten_mesh_indices
utils3d.np.flatten_mesh_indices(args) -
utils3d.graph_connected_components
Compute connected components of an undirected graph.
utils3d.np.graph_connected_components(edges, num_vertices) utils3d.pt.graph_connected_components(edges, num_vertices)
utils3d.laplacian_hc_smooth_mesh
HC algorithm from Improved Laplacian Smoothing of Noisy Surface Meshes by J.Vollmer et al.
- utils3d.pt.laplacian_hc_smooth_mesh(vertices, faces, times, alpha, beta, weight)
utils3d.laplacian_smooth_mesh
Laplacian smooth with cotangent weights
- utils3d.pt.laplacian_smooth_mesh(vertices, faces, weight, times)
utils3d.merge_duplicate_vertices
Merge duplicate vertices of a triangular mesh.
utils3d.np.merge_duplicate_vertices(vertices, faces, tol) utils3d.pt.merge_duplicate_vertices(vertices, faces, tol)
utils3d.merge_meshes
Merge multiple meshes into one mesh. Vertices will be no longer shared.
utils3d.np.merge_meshes(meshes) -
utils3d.mesh_adjacency_graph
Get adjacency graph of a mesh.
utils3d.np.mesh_adjacency_graph(adjacency, faces, edges, num_vertices, self_loop) -
utils3d.mesh_connected_components
Compute connected faces of a mesh.
utils3d.np.mesh_connected_components(faces, num_vertices) utils3d.pt.mesh_connected_components(faces, num_vertices)
utils3d.mesh_dual_graph
Get dual graph of a mesh. (Mesh face as dual graph's vertex, adjacency by edge sharing)
- utils3d.pt.mesh_dual_graph(faces)
utils3d.mesh_edges
Get undirected edges of a mesh. Optionally return additional mappings.
utils3d.np.mesh_edges(faces, return_face2edge, return_edge2face, return_counts) utils3d.pt.mesh_edges(faces, return_face2edge, return_edge2face, return_counts)
utils3d.mesh_half_edges
Get half edges of a mesh. Optionally return additional mappings.
utils3d.np.mesh_half_edges(faces, return_face2edge, return_edge2face, return_twin, return_next, return_prev, return_counts) utils3d.pt.mesh_half_edges(faces, return_face2edge, return_edge2face, return_twin, return_next, return_prev, return_counts)
utils3d.remove_corrupted_faces
Remove corrupted faces (faces with duplicated vertices)
utils3d.np.remove_corrupted_faces(faces) utils3d.pt.remove_corrupted_faces(faces)
utils3d.remove_isolated_pieces
Remove isolated pieces of a mesh.
- utils3d.pt.remove_isolated_pieces(vertices, faces, connected_components, thresh_num_faces, thresh_radius, thresh_boundary_ratio, remove_unreferenced)
utils3d.remove_unused_vertices
Remove unreferenced vertices of a mesh.
utils3d.np.remove_unused_vertices(faces, vertice_attrs, return_indices) utils3d.pt.remove_unused_vertices(faces, vertice_attrs, return_indices)
utils3d.subdivide_mesh
Subdivide a triangular mesh by splitting each triangle into 4 smaller triangles.
utils3d.np.subdivide_mesh(vertices, faces, level) utils3d.pt.subdivide_mesh(vertices, faces, n)
utils3d.taubin_smooth_mesh
Taubin smooth mesh
- utils3d.pt.taubin_smooth_mesh(vertices, faces, lambda_, mu_)
utils3d.triangulate_mesh
Triangulate a polygonal mesh.
utils3d.np.triangulate_mesh(faces, vertices, method, return_face_indices) utils3d.pt.triangulate_mesh(faces, vertices, method)

Point Sampling

Function Numpy Pytorch
utils3d.hierarchical_voxel_sampling
Select approximately a target number of spatially distributed original points.
utils3d.np.hierarchical_voxel_sampling(points, num_samples) utils3d.pt.hierarchical_voxel_sampling(points, num_samples)
utils3d.voxel_grid_sampling
Select one original point per occupied cubic voxel.
utils3d.np.voxel_grid_sampling(points, voxel_size) utils3d.pt.voxel_grid_sampling(points, voxel_size)

Rasterization

Function Numpy Pytorch
utils3d.RastContext
Context for numpy-side rasterization. Based on moderngl.
utils3d.np.RastContext(args, kwargs) -
utils3d.rasterize_lines
Rasterize lines.
utils3d.np.rasterize_lines(size, vertices, attributes, attributes_domain, lines, view, projection, extrinsics, intrinsics, near, far, line_width, return_depth, return_interpolation, background, ctx) utils3d.pt.rasterize_lines(size, vertices, attributes, attributes_domain, lines, view, projection, extrinsics, intrinsics, near, far, line_width, return_depth, return_interpolation, background)
utils3d.rasterize_point_cloud
Rasterize point cloud.
utils3d.np.rasterize_point_cloud(size, points, point_sizes, point_size_in, point_shape, attributes, view, projection, extrinsics, intrinsics, near, far, return_depth, return_point_id, background, ctx) utils3d.pt.rasterize_point_cloud(size, points, point_sizes, point_size_in, point_shape, attributes, view, projection, extrinsics, intrinsics, near, far, return_depth, return_point_id, background)
utils3d.rasterize_triangles
Rasterize triangles.
utils3d.np.rasterize_triangles(size, vertices, attributes, attributes_domain, faces, view, projection, extrinsics, intrinsics, near, far, cull_backface, return_depth, return_interpolation, background, ctx) utils3d.pt.rasterize_triangles(size, vertices, attributes, attributes_domain, faces, view, projection, extrinsics, intrinsics, near, far, cull_backface, return_depth, return_interpolation, background)
utils3d.rasterize_triangles_peeling
Rasterize triangles with depth peeling.
utils3d.np.rasterize_triangles_peeling(size, vertices, attributes, attributes_domain, faces, view, projection, extrinsics, intrinsics, near, far, cull_backface, return_depth, return_interpolation, ctx) utils3d.pt.rasterize_triangles_peeling(size, vertices, attributes, attributes_domain, faces, view, projection, extrinsics, intrinsics, near, far, cull_backface, return_depth, return_interpolation)
utils3d.sample_texture
Sample from a texture map with a UV map.
utils3d.np.sample_texture(uv_map, texture_map, interpolation, mipmap_level, repeat, anisotropic, ctx) -
utils3d.test_rasterization
Test if rasterization works. It will render a cube with random colors and save it as a CHECKME.png file.
utils3d.np.test_rasterization(ctx) -

Array Utils

Function Numpy Pytorch
utils3d.csr_eliminate_zeros
Remove zero elements from a sparse CSR tensor.
- utils3d.pt.csr_eliminate_zeros(input)
utils3d.csr_matrix_from_dense_indices
Convert 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.group
Split the data into groups based on the provided labels.
utils3d.np.group(labels, data) utils3d.pt.group(labels, data)
utils3d.index_reduce
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.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.lexsort
Perform lexicographical sort on multiple keys. Like numpy.lexsort.
- utils3d.pt.lexsort(keys, dim)
utils3d.lookup
Look up query in key like a dictionary. Useful for COO indexing.
utils3d.np.lookup(key, query) utils3d.pt.lookup(key, query)
utils3d.lookup_get
Dictionary-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_set
Dictionary-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_max
Similar to torch.max, but with mask
- utils3d.pt.masked_max(input, mask, dim, keepdim)
utils3d.masked_min
Similar to torch.min, but with mask
- utils3d.pt.masked_min(input, mask, dim, keepdim)
utils3d.matrix_trace
Compute the trace of a batch of matrices
- utils3d.pt.matrix_trace(input, dim1, dim2)
utils3d.max_pool_2d
utils3d.np.max_pool_2d(x, kernel_size, stride, padding, axis) -
utils3d.pooling
Compute the pooling of the input array.
utils3d.np.pooling(x, kernel_size, stride, padding, axis, mode) -
utils3d.reverse_permutation
Compute the reverse of a permutation array.
utils3d.np.reverse_permutation(perm, axis) utils3d.pt.reverse_permutation(perm, dim)
utils3d.scatter_argmax
Scatter 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_argmin
Scatter 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_window
Get 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)
utils3d.vector_outer
Compute the outer product of two arrays.
utils3d.np.vector_outer(x, y) utils3d.pt.vector_outer(x, y)

Segment Array Operations

Function Numpy Pytorch
utils3d.group_as_segments
Group 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_argmax
Compute 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_argmin
Compute 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_argsort
Compute the argsort indices within each segment.
- utils3d.pt.segment_argsort(input, offsets, descending, dim)
utils3d.segment_chain
Concatenate segmented arrays in sequence. The number of segments are summed.
utils3d.np.segment_chain(segments, axis) utils3d.pt.segment_chain(segments, axis)
utils3d.segment_combinations
Generate 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_concatenate
Concatenate 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_cumsum
Compute 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_median
Compute the median of each segment.
- utils3d.pt.segment_median(input, offsets, dim)
utils3d.segment_multinomial
Perform multinomial sampling within each segment.
- utils3d.pt.segment_multinomial(weights, offsets, num_samples, eps, replacement)
utils3d.segment_roll
Roll the data within each segment.
utils3d.np.segment_roll(data, offsets, shift, axis) utils3d.pt.segment_roll(data, offsets, shift, dim)
utils3d.segment_searchsorted
Per-segment searchsorted operation implemented with triton.
- utils3d.pt.segment_searchsorted(sorted_sequence, offsets, input, segment_ids, side)
utils3d.segment_sort
Sort the data within each segment.
- utils3d.pt.segment_sort(input, offsets, descending, dim)
utils3d.segment_sum
Compute 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_take
Take some segments from a segmented array
utils3d.np.segment_take(data, offsets, taking, axis) utils3d.pt.segment_take(data, offsets, taking, dim)
utils3d.segment_topk
Select the top-k values and indices within each segment.
- utils3d.pt.segment_topk(input, offsets, k, largest, dim)
utils3d.stack_segments
Stack segments into a padded tensor.
- utils3d.pt.stack_segments(input, offsets, max_length, padding_value, dim)

IO

Function Numpy Pytorch
utils3d.read_extrinsics_from_colmap
Read extrinsics from colmap images.txt file.
utils3d.np.read_extrinsics_from_colmap(file) -
utils3d.read_intrinsics_from_colmap
Read intrinsics from colmap cameras.txt file.
utils3d.np.read_intrinsics_from_colmap(file, normalize) -
utils3d.read_obj
Read wavefront .obj file.
utils3d.np.read_obj(file, encoding, ignore_unknown) -
utils3d.read_ply
Read a PLY file. Supports arbitrary properties, polygonal meshes. Very fast.
utils3d.np.read_ply(file) -
utils3d.write_extrinsics_as_colmap
Write extrinsics to colmap images.txt file.
utils3d.np.write_extrinsics_as_colmap(file, extrinsics, image_names, camera_ids) -
utils3d.write_intrinsics_as_colmap
Write 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_ply
Write a PLY file. Supports arbitrary properties, polygonal meshes.
utils3d.np.write_ply(file, data, format_) -

About

A collection of useful functions for 3D vision & graphics research in Python.

Resources

Stars

294 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages