A production-grade maritime surveillance system for detecting ships in Synthetic Aperture Radar (SAR) imagery using Oriented Bounding Boxes (OBB) and speckle noise filtering.
Detect ships in SAR images where vessels appear as noisy "salt-and-pepper" clusters, using:
- Lee Speckle Filter: Remove radar-specific multiplicative noise
- YOLOv8-OBB: Detect ships with rotated bounding boxes (ships are rarely horizontal)
SAR images suffer from "speckle noise" - a granular interference pattern unique to coherent radar imaging. Ships appear as bright clusters mixed with noise, making standard detection difficult.
The Lee filter removes multiplicative radar noise while preserving ship edges:
Before Lee Filter: After Lee Filter:
ββββββββββββββββ ββββββββββββββββ
ββββββββββββββββ ββββββββββββββββ
ββββββββββββββββ β ββββββββββββββββ
ββββββββββββββββ ββββββββββββββββ
ββββββββββββββββ ββββββββββββββββ
Ships sail in arbitrary directions. Axis-aligned boxes waste pixels and overlap:
Standard Box (AABB): Oriented Box (OBB):
βββββββββββββββββββ β±βββββββββββββ²
β ββββββββ β β±βββββββββββββ²
β ββββββββ β β β²βββββββββββββ±
β βββββ β β²βββββββββββββ±
βββββββββββββββββββ
60% background! Tight fit!
| Single Ship | Multiple Ships | Complex Scene |
|---|---|---|
![]() |
![]() |
![]() |
Trident/
βββ src/
β βββ __init__.py # Package initialization
β βββ data_manager.py # Kaggle download, COCOβYOLO conversion
β βββ preprocessing.py # Lee speckle filter implementation
β βββ train.py # YOLOv8-OBB training pipeline
β βββ inference.py # Detection and visualization
βββ config/
β βββ config.yaml # Configuration parameters
βββ scripts/
β βββ generate_samples.py # Generate sample outputs
βββ assets/ # README images
βββ data/ # Dataset storage
βββ output/ # Detection results
βββ requirements.txt
# Clone the repository
git clone https://github.com/yourusername/Trident.git
cd Trident
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Configure API credentials
# 1. Go to kaggle.com β Settings β Create New API Token
# 2. Create credentials file:
mkdir -p ~/.kaggle
echo '{"username":"YOUR_USERNAME","key":"YOUR_API_KEY"}' > ~/.kaggle/kaggle.json
chmod 600 ~/.kaggle/kaggle.json# Download SSDD from Kaggle and prepare YOLO OBB format
python src/data_manager.py --download --prepare --data-root ./data# Train with default settings (YOLOv8n-OBB)
python src/train.py --data ./data/ssdd_yolo_obb/data.yaml
# Train with custom settings
python src/train.py \
--data ./data/ssdd_yolo_obb/data.yaml \
--model yolov8s-obb \
--epochs 150 \
--batch 32 \
--imgsz 640# Demo mode (random validation images)
python src/inference.py \
--model ./trident_sar/ship_detection/weights/best.pt \
--data ./data/ssdd_yolo_obb/data.yaml \
--output ./output
# Single image
python src/inference.py \
--model ./trident_sar/ship_detection/weights/best.pt \
--source /path/to/sar_image.jpg \
--output ./outputEdit config/config.yaml to customize:
preprocessing:
lee_filter:
window_size: 7 # Larger = more smoothing
model:
variant: "yolov8n-obb" # n/s/m/l/x variants
image_size: 640
training:
epochs: 100
batch_size: 16
learning_rate: 0.001| Model | Size | Speed | Accuracy |
|---|---|---|---|
| yolov8n-obb | 3.2M | Fastest | Good |
| yolov8s-obb | 11.2M | Fast | Better |
| yolov8m-obb | 25.9M | Medium | High |
| yolov8l-obb | 43.7M | Slow | Higher |
| yolov8x-obb | 68.2M | Slowest | Highest |
from src.preprocessing import SARPreprocessor, apply_lee_filter
from src.inference import SARShipDetector
# Preprocess a SAR image
preprocessor = SARPreprocessor(lee_window_size=7)
filtered = preprocessor.process(sar_image)
# Detect ships
detector = SARShipDetector(
model_path="trident_sar/ship_detection/weights/best.pt",
confidence_threshold=0.25
)
result = detector.detect("path/to/sar_image.jpg")
print(f"Ships detected: {result['count']}")
for det in result['detections']:
print(f" Confidence: {det['confidence']:.2f}")
print(f" Angle: {det['angle']:.1f}Β°")Detection results include:
corners: 4 corner points of the rotated boxcenter: Center coordinateswidth,height: Box dimensionsangle: Rotation angle in degreesconfidence: Detection confidence
The SAR Ship Detection Dataset (SSDD) used in this project:
- Source: Kaggle - SARscope Maritime Images
- Train: 4,716 images
- Validation: 1,346 images
- Format: COCO JSON (converted to YOLO OBB)
The Lee filter assumes multiplicative noise: I = R Γ N
RΜ = ΞΌ + W Γ (I - ΞΌ)
W = ΟΒ² / (ΟΒ² + Ο_noiseΒ²)
Where:
ΞΌ= local meanΟΒ²= local varianceW= adaptive weight (preserves edges)
YOLO OBB format: class x1 y1 x2 y2 x3 y3 x4 y4
Four normalized corner coordinates defining the rotated rectangle.
MIT License - see LICENSE for details.
- SSDD Dataset creators
- Ultralytics YOLOv8 team
- Jong-Sen Lee (Lee filter inventor, 1981)





