---
estimated_steps: 11
estimated_files: 3
skills_used: []
---

# T02: OpenCV preprocessing pipeline

1. Create engine/pipeline/preprocessing.py
2. Implement preprocessing stages in order:
   - Grayscale conversion
   - Denoise (bilateral filter, tunable d/sigmaColor/sigmaSpace)
   - Contrast enhancement (CLAHE, tunable clipLimit/tileGridSize)
   - Threshold (Otsu auto-threshold default, manual override)
   - Edge detection (optional Canny, tunable thresholds)
   - Morphological ops (dilation/erosion, tunable kernel size/iterations)
3. Each stage tunable via parameters dict
4. Pipeline accepts raw image bytes, returns processed numpy array
5. Add unit tests for each stage

## Inputs

- `GSD-INITIATE.md`

## Expected Output

- `engine/pipeline/preprocessing.py`
- `engine/tests/test_preprocessing.py`

## Verification

cd engine && python -m pytest tests/test_preprocessing.py -v
