okaneco / kmeans-colors

k-means clustering library and binary to find dominant colors in images
Apache License 2.0
132 stars 9 forks source link

Speed up `Lab` conversion with `Srgb`/`LinSrgb` fast path, use `palette` `FromStr` impl #55

Closed okaneco closed 1 year ago

okaneco commented 1 year ago

Speedup gains increase as image size increases. On a 4500x3000 image, a 44% speedup was seen reducing the total time to calculate centroids from 7.8s to 4.3s after switching from into_format to using into_linear. The speedup is closer to 15-17% on smaller images (320x200) but still noticeable when measured.

Example speedups for reading in images in Rgb, converting them to Lab, and calculating the centroids. Prompted from this discussion https://github.com/Ogeon/palette/discussions/341#discussioncomment-6561118 Image Size into_format into_linear
4547x3032 7.8s 4.3s
1700x2200 2.4s 1.3s
805x1000 0.48s 0.35s
320x206 0.056s 0.046s