This repository contains Python scripts for lane marking labeling and segmentation in image sequences. The scripts facilitate manual labeling of lane points and automate the labeling process for subsequent frames. Additionally, segmentation masks are generated from the labeled points for training purposes.
This script implements the Hybrid Interactive and Automated Labeling Method compatible with specialized neural network architectures such as CLRerNet. It combines manual point annotations with automated propagation across sequential image frames to significantly reduce manual effort.
- Implements Algorithm 1 from the research paper
- Manual annotation of critical lane points on selected frames (every σ frames)
- Automated propagation of annotations to intermediate frames using directional translation
- Generates binary segmentation masks compatible with CLRerNet architecture
- Significantly reduces manual effort compared to CDLEM and ALINA methods
- Higher annotation consistency and scalability
python hybrid_labeling.pyModify the configuration in the main() function:
input_dir: Directory containing image sequenceoutput_dir: Directory for annotation outputstep_size: Frames between manual annotations (σ parameter)adjustment_factor: Scaling factor for directional translation
- Left click: Select lane points
- 'k' key: Save current lane and start a new one
- Arrow keys: Set direction (Left, Right, Up, Down, default: Straight)
- 'r' key: Redo current frame
- Enter: Finish selection and proceed
The hybrid method processes image sequences in two phases:
- Interactive Labeling: Manual annotation every σ frames with directional translation to intermediate frames
- Mask Generation: Automatic creation of binary segmentation masks from all annotations
This script allows for manual annotation of lane markings on images and automates the labeling process for subsequent frames. The user manually selects lane points, and the script generates .lines.txt files containing the labeled points. It also enables automatic adjustment of lane points for consecutive frames based on user-defined directions.
- Allows manual selection of lane points on an image.
- Supports setting lane directions (left, right, up, down, straight) using arrow keys.
- Saves labeled points in
.lines.txtfiles. - Automates lane point adjustments for subsequent frames.
- Displays annotated frames for visualization.
Modify the input_dir and output_dir variables to match your dataset structure. Run:
python manual_labeling.py- Mouse Left-click: Select a lane point.
- 'k' key: Save the current lane and start a new one.
- Arrow keys: Set direction (Left, Right, Up, Down, default is Straight).
- 'Enter' key: Finish selection and proceed.
This script generates segmentation masks from lane markings stored in .lines.txt files. It reads image paths from train.txt, processes each image, and creates segmentation masks by connecting lane points with lines.
- Reads labeled points from
.lines.txtfiles. - Generates binary lane segmentation masks.
- Saves masks in a new directory (
laneseg_label_w16/images). - Updates the training file with new image-mask paths.
Modify the base_dir variable to your dataset location. Run:
python make_seg.py- The masks are saved as
.pngfiles inlaneseg_label_w16/images. - The updated
x_train.txtfile contains new image-mask paths.
Ensure you have the required dependencies installed:
pip install opencv-python numpyThe hybrid labeling method implements the following mathematical procedure:
Algorithm 1: Hybrid Interactive and Automated Labeling Method
Input: Image sequence I = {I₁, I₂, ..., Iₙ}
Output: Lane annotations L and segmentation masks M compatible with CLRerNet
- Initialize frame index i ← 1, step size σ
- While i ≤ N:
- Manually select lane points Pᵢ = {(xⱼ, yⱼ)} on image Iᵢ
- Define lane direction δ ∈ {left, right, up, down, straight}
- Save points Pᵢ and direction δ to annotation file
- For k = i+1 to min(i + σ - 1, N):
- Adjust points using directional translation: Pₖ = Pᵢ + (k - i) · γ(δ)
- Propagate adjusted points Pₖ to frame Iₖ
- Save annotations for frame Iₖ
- i ← i + σ
- For all annotated frames Iᵢ:
- Generate segmentation masks Mᵢ by interpolating lane points
- Mᵢ(x,y) = 1 if (x,y) in lane segment, 0 otherwise
- Save segmentation masks Mᵢ
Key Advantages:
- Reduced Manual Effort: Only annotate every σ frames instead of every frame
- Consistency: Automated propagation ensures consistent annotations
- Compatibility: Output format optimized for CLRerNet architecture
- Scalability: Efficiently handles large datasets with diverse conditions
repo/
│── hybrid_labeling.py # Hybrid labeling algorithm (Recommended)
│── manual_labeling.py # Legacy manual labeling script
│── make_seg.py # Legacy segmentation mask generation script
│── validate_labeling # Validation script for labeled data
│── datasets/
│ ├── assisttaxi2/
│ │ ├── train/
│ │ │ ├── images/ # Original images
│ │ │ ├── train.txt # List of training images
│ │ │ ├── laneseg_label_w16/ # Output segmentation masks
│ │ ├── valid/
│ │ │ ├── images2/ # Validation images
│ │ │ ├── processed_images/ # Processed images with annotations
│ │ │ ├── segmentation_masks/ # Generated segmentation masks
- Ensure images are stored in the correct directories before running the scripts.
- Adjust
step_sizeandadjustment_factorinmanual_labeling.pyfor optimal automation.