torch_ransac3d package¶
Submodules¶
torch_ransac3d.line module¶
- torch_ransac3d.line.line_fit(pts, thresh=0.01, max_iterations=1000, iterations_per_batch=1, epsilon=1e-08, device=device(type='cpu'))¶
Fit a line using a RANSAC-like method in a batched approach.
This function fits a line to a 3D point cloud using a RANSAC-like method, processing multiple iterations in parallel for efficiency.
- Parameters:
pts (torch.Tensor) – 3D point cloud.
thresh (float) – Threshold distance to consider a point as an inlier.
max_iterations (int) – Maximum number of iterations for the RANSAC loop.
iterations_per_batch (int) – Number of iterations processed in each batch.
epsilon (float) – Small value to avoid division by zero.
device (torch.device) – Device to run the computations on.
- Returns:
A tuple containing: - best_line_direction (torch.Tensor): Best line direction vector found (shape: (3,)) - best_line_point (torch.Tensor): A point on the best line found (shape: (3,)) - best_inlier_indices (torch.Tensor): Indices of points considered inliers
- Return type:
Tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Example
>>> pts = torch.randn(1000, 3) >>> direction, point, inlier_indices = line_fit(pts) >>> print(f"Line direction: {direction}") >>> print(f"Point on line: {point}") >>> print(f"Number of inliers: {inlier_indices.shape[0]}")
torch_ransac3d.plane module¶
- torch_ransac3d.plane.plane_fit(pts, thresh=0.05, max_iterations=1000, iterations_per_batch=1, epsilon=1e-08, device=device(type='cpu'))¶
Find the best equation for a plane using a batched RANSAC approach.
This function fits a plane to a 3D point cloud using a RANSAC-like method, processing multiple iterations in parallel for efficiency.
- Parameters:
pts (torch.Tensor) – 3D point cloud.
thresh (float) – Threshold distance from the plane to consider a point as an inlier.
max_iterations (int) – Maximum number of iterations for the RANSAC algorithm.
iterations_per_batch (int) – Number of iterations to process in parallel.
epsilon (float) – Small value to avoid division by zero.
device (torch.device) – Device to run the computations on.
- Returns:
A tuple containing: - equation (torch.Tensor): Parameters of the plane equation Ax+By+Cz+D (shape: (1, 4)) - inliers (torch.Tensor): Points from the dataset considered as inliers
- Return type:
Tuple[torch.Tensor, torch.Tensor]
Example
>>> pts = torch.randn(1000, 3) >>> equation, inliers = plane_fit(pts) >>> print(f"Plane equation: {equation}") >>> print(f"Number of inliers: {inliers.shape[0]}")
torch_ransac3d.sphere module¶
- torch_ransac3d.sphere.sphere_fit(pts, thresh=0.05, max_iterations=1000, iterations_per_batch=1, epsilon=1e-08, device=device(type='cpu'))¶
Find the best parameters (center and radius) for a sphere using a batched RANSAC approach.
This function fits a sphere to a 3D point cloud using a RANSAC-like method, processing multiple iterations in parallel for efficiency.
- Parameters:
pts (torch.Tensor) – 3D point cloud.
thresh (float) – Threshold distance from the sphere surface to consider a point as an inlier.
max_iterations (int) – Maximum number of iterations for the RANSAC algorithm.
iterations_per_batch (int) – Number of iterations to process in parallel.
epsilon (float) – Small value to avoid division by zero.
device (torch.device) – Device to run the computations on.
- Returns:
A tuple containing: - best_center (torch.Tensor): Center of the sphere (shape: (3,)) - best_radius (float): Radius of the sphere - best_inlier_indices (torch.Tensor): Indices of points from the dataset considered as inliers
- Return type:
Tuple[torch.Tensor, float, torch.Tensor]
Example
>>> pts = torch.randn(1000, 3) >>> center, radius, inlier_indices = sphere_fit(pts) >>> print(f"Sphere center: {center}") >>> print(f"Sphere radius: {radius}") >>> print(f"Number of inliers: {inlier_indices.shape[0]}")