API

class segment_lidar.samlidar.SamLidar(ckpt_path: str, algorithm: str = 'segment-geospatial', model_type: str = 'vit_h', resolution: float = 0.25, height: int = 512, width: int = 512, distance_threshold: float | None = None, device: str = 'cuda:0', sam_kwargs: bool = False, intrinsics: ndarray | None = None, rotation: ndarray | None = None, translation: ndarray | None = None, interactive: bool = False)

Bases: object

csf(points: ndarray, class_threshold: float = 0.5, cloth_resolution: float = 0.2, iterations: int = 500, slope_smooth: bool = False, csf_path: str | None = None, exists: bool = False) Tuple[ndarray, ndarray, ndarray]

Applies the CSF (Cloth Simulation Filter) algorithm to filter ground points in a point cloud.

Parameters:
  • points (np.ndarray) – The input point cloud as a NumPy array, where each row represents a point with x, y, z coordinates.

  • class_threshold (float, optional) – The threshold value for classifying points as ground/non-ground, defaults to 0.5.

  • cloth_resolution (float, optional) – The resolution value for cloth simulation, defaults to 0.2.

  • iterations (int, optional) – The number of iterations for the CSF algorithm, defaults to 500.

  • slope_smooth (bool, optional) – A boolean indicating whether to enable slope smoothing, defaults to False.

  • csf_path (str, optional) – The path to save the results, defaults to None.

  • exists (bool, optional) – A boolean indicating whether the results already exist, defaults to False.

Returns:

A tuple containing three arrays: the filtered point cloud, non-ground (filtered) points indinces and ground points indices.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

class mask(crop_n_layers: int = 1, crop_n_points_downscale_factor: int = 1, min_mask_region_area: int = 200, points_per_side: int = 5, pred_iou_thresh: float = 0.9, stability_score_thresh: float = 0.92)

Bases: object

read(path: str, classification: int | None = None) ndarray

Reads a point cloud from a file and returns it as a NumPy array.

Parameters:
  • path (str) – The path to the input file.

  • classification (int, optional) – The optional classification value to filter the point cloud, defaults to None.

Returns:

The point cloud as a NumPy array.

Return type:

np.ndarray

Raises:

ValueError – If the input file format is not supported.

segment(points: ~numpy.ndarray, view: ~segment_lidar.view.TopView | ~segment_lidar.view.PinholeView = <segment_lidar.view.TopView object>, image_path: str = 'raster.tif', labels_path: str = 'labeled.tif', image_exists: bool = False, label_exists: bool = False) Tuple[ndarray, ndarray, ndarray]

Segments a point cloud based on the provided parameters and returns the segment IDs, original image, and segmented image.

Parameters:
  • points (np.ndarray) – The point cloud data as a NumPy array.

  • view (Union[TopView, PinholeView]) – The viewpoint to use for segmenting the point cloud, defaults to TopView().

  • image_path (str) – Path to the input raster image, defaults to ‘raster.tif’.

  • labels_path (str) – Path to save the labeled output image, defaults to ‘labeled.tif’.

  • image_exists (bool) – A boolean indicating whether the raster image already exists, defaults to False.

  • label_exists (bool) – A boolean indicating whether the labeled image already exists, defaults to False.

Returns:

A tuple containing the segment IDs, segmented image, and RGB image.

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

class text_prompt(text: str | None = None, box_threshold: float = 0.24, text_threshold: float = 0.15)

Bases: object

write(points: ndarray, segment_ids: ndarray, non_ground: ndarray | None = None, ground: ndarray | None = None, save_path: str = 'segmented.las', ground_path: str | None = None) None

Writes the segmented point cloud data to a LAS/LAZ file.

Parameters:
  • points (np.ndarray) – The input point cloud data as a NumPy array, where each row represents a point with x, y, z coordinates.

  • segment_ids (np.ndarray) – The segment IDs corresponding to each point in the point cloud.

  • non_ground (np.ndarray, optional) – Optional array of indices for non-ground points in the original point cloud (default: None).

  • ground (np.ndarray, optional) – Optional array of indices for ground points in the original point cloud (default: None).

  • save_path (str, optional) – The path to save the segmented LAS/LAZ file (default: ‘segmented.las’).

Returns:

None

class segment_lidar.view.PinholeView(interactive: bool = True)

Bases: object

The PinholeView class converts a point cloud to a pinhole camera view image and vice versa.

cloud_to_image(points: ndarray, resolution: float = 0.1, rotation: ndarray | None = None, translation: ndarray | None = None, intrinsics: ndarray | None = None, distance_threshold: float | None = None) Tuple[ndarray, ndarray, ndarray]

Converts a point cloud to an image.

Parameters:
  • extrinsics (ndarray (4x4)) – The extrinsics matrix of the camera.

  • intrinsics (ndarray (width, height, fx, fy, cx, cy) (6x1)) – The intrinsics matrix of the camera.

  • points (ndarray) – An array of points in the cloud, where each row represents a point. The array shape can be (N, 3) or (N, 6). If the shape is (N, 3), each point is assumed to have white color (255, 255, 255). If the shape is (N, 6), the last three columns represent the RGB color values for each point.

  • resolution (float) – The resolution of the image in units per pixel.

  • distance_threshold (float) – An optional distance threshold. Points with distances greater than this threshold are ignored.

Returns:

A tuple containing: - An image array representing the point cloud, where each pixel contains the RGB color values of the corresponding point in the cloud. - An array of pixel x-coordinates in the image. - An array of pixel y-coordinates in the image.

Return type:

tuple of ndarrays

Raises:

ValueError – If the shape of the points array is not valid or if any parameter is invalid.

image_to_cloud(points: ndarray, image: ndarray, intrinsics: ndarray, extrinsics: ndarray) ndarray

Converts an image to a point cloud.

Parameters:
  • points (ndarray) – An array of points in the cloud, where each row represents a point.

  • image (ndarray) – An image array representing the point cloud, where each pixel contains the RGB color values of the corresponding point in the cloud.

  • intrinsics (ndarray (width, height, fx, fy, cx, cy) (6x1)) – The intrinsics matrix of the camera.

  • extrinsics (ndarray (4x4)) – The extrinsics matrix of the camera.

Returns:

An array of segments’ IDs in the cloud, where each row represents the segment’s ID of a point.

Return type:

ndarray

class segment_lidar.view.TopView

Bases: object

The TopView class converts a point cloud to a top view image and vice versa.

cloud_to_image(points: ndarray, resolution: float) ndarray

Converts a point cloud to a planar image.

Parameters:
  • points (ndarray) – An array of points in the cloud, where each row represents a point. The array shape can be (N, 3) or (N, 6). If the shape is (N, 3), each point is assumed to have white color (255, 255, 255). If the shape is (N, 6), the last three columns represent the RGB color values for each point.

  • minx (float) – The minimum x-coordinate value of the cloud bounding box.

  • maxx (float) – The maximum x-coordinate value of the cloud bounding box.

  • miny (float) – The minimum y-coordinate value of the cloud bounding box.

  • maxy (float) – The maximum y-coordinate value of the cloud bounding box.

  • resolution (float) – The resolution of the image in units per pixel.

Returns:

An image array representing the point cloud, where each pixel contains the RGB color values of the corresponding point in the cloud.

Return type:

ndarray

Raises:

ValueError – If the shape of the points array is not valid or if any parameter is invalid.

image_to_cloud(points: ndarray, image: ndarray, resolution: float) ndarray

Converts an image to a point cloud.

Parameters:
  • points (ndarray) – An array of points in the cloud, where each row represents a point. The array shape can be (N, 3) or (N, 6). If the shape is (N, 3), each point is assumed to have white color (255, 255, 255). If the shape is (N, 6), the last three columns represent the RGB color values for each point.

  • image (ndarray) – An image array representing the point cloud, where each pixel contains the RGB color values of the corresponding point in the cloud.

  • resolution (float) – The resolution of the image in units per pixel.

Returns:

An array of segments’ IDs in the cloud, where each row represents the segment’s ID of a point.

Return type:

ndarray

Raises:

ValueError – If the shape of the points array is not valid or if any parameter is invalid.