perf: Replace O(n²) color clustering with scipy.spatial.cKDTree #22
Labels
No labels
blocked:children
blocked:depends-101
blocked:depends-103
blocked:depends-104
blocked:needs-attention
blocked:needs-decision
blocked:no-changes
blocked:preflight
bug
chore
feature-request
in-progress
lint-cleanup
needs-decompose
performance
quality
quickfix
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/easystitch#22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
image_processor.py:318andcolor_quantizer.py:295use nested loops to compare every pair of unique colors via Delta E. This is O(n²) where n = number of unique colors. Each Delta E calculation involves CIELAB conversion and Euclidean distance.For images with 100-500 unique colors after quantization, this means 5K-125K expensive Delta E computations.
Proposed Fix
Pre-compute LAB values for all unique colors in a single batch, then use
scipy.spatial.cKDTreefor nearest-neighbor clustering:Impact
5-20x faster for images with many unique colors.
Files
src/raster/image_processor.py:318-336src/raster/color_quantizer.py:295-320