This module provides functionality for preprocessing 3D point clouds with semantic labels by projecting them onto 2D images and assigning colors/labels through various voting strategies.
- Multiple Voting Algorithms: Support for majority voting, probability-based voting, and correlation-based voting
- COLMAP Integration: Compatible with both binary and text COLMAP formats
- Flexible Input: Supports both color and label images
- PLY Output: Generates standard PLY files with semantic labels
python ply_preprocessing.py --dataset_path /path/to/dataset --algorithm corr --output_ply_name points3D_corr.ply--dataset_path: Path to the dataset directory (default:datasets/lerf_mask)--algorithm: Voting algorithm to use. Options:majority,prob,corr(default:corr)--output_ply_name: Output PLY file name (default:points3D_corr.ply)
- Assigns the most frequently occurring label to each 3D point
- Simple and robust approach
- Best for datasets with consistent labeling
- Samples labels based on their probability distribution
- Introduces controlled randomness
- Useful for handling ambiguous regions
- Uses COLMAP track correspondences for more accurate assignment
- Leverages geometric consistency
- Recommended for high-accuracy requirements
The script expects the following directory structure for each dataset:
dataset_folder/
├── object_mask/ # Label images (grayscale)
├── color_mask/ # Optional: Color images (RGB)
└── sparse/0/ # COLMAP sparse reconstruction
├── cameras.bin # Camera parameters
├── images.bin # Image poses
└── points3D.bin # 3D points
Alternative COLMAP format:
dataset_folder/
├── object_mask/
├── color_mask/
└── colmap/
├── cameras_undistorted.txt
├── images.txt
└── points3D.txt
The generated PLY file contains the following attributes for each point:
x, y, z: 3D coordinatesnx, ny, nz: Normal vectors (set to zero)red, green, blue: RGB color valueslabel: Semantic label ID
Converts object IDs to unique RGB colors for visualization.
majority_voting(): Implements majority voting strategyprob_voting(): Implements probability-based voting strategycorr_voting(): Implements correlation-based voting strategystorePly(): Saves point cloud to PLY format
project_points(): Projects 3D points to 2D image planeget_point_colors_from_image(): Extracts colors and labels from imagesquaternion_to_rotation_matrix(): Converts quaternions to rotation matrices
- OpenCV (
cv2) - NumPy
- PLY file handling (
plyfile) - COLMAP loader utilities
MIT License - See the main repository for details.