4 ms·
Author here: the library just accepts RGB8 bitmaps, probably coming either from Rust's image crate [1] or Python's Pillow [2], which are both mature and widely
by dgroshev 7mo ago
Author here: the library just accepts RGB8 bitmaps, probably coming either from Rust's image crate [1] or Python's Pillow [2], which are both mature and widely used. Dealing with codecs is way out of scope.
As for loading into memory at once: I suppose I could integrate with something like libvips and stream strips out of the decoded image without holding the entire bitmap, but that'd require substantially more glue and complexity. The current approach works fine for extracting dominant colours once to save in a database.
You're right that pre-resizing the images makes everything faster, but keep in mind that k-means still requires a pretty nontrivial amount of computation.
[1]: https://crates.io/crates/image https://crates.io/crates/image
[2]: https://pypi.org/project/pillow/ https://pypi.org/project/pillow/
- hedgehog 7mo agoIf you ever did want to wrap this in code processing untrusted images there's a library called "glycin" designed for that purpose (it's used by Loupe, the default Gnome image viewer). https://gnome.pages.gitlab.gnome.org/glycin/ https://gnome.pages.gitlab.gnome.org/glycin/
- jcupitt 7mo agoHello, libvips author here, you can get it to do the OKLab averaging for you. For example, using pyvips (ahem, untested): image = pyvips.Image.new_from_file(filename, access="sequential") scale = min(200 / image.width, 200 / image.height) thumbnail = image.colourspace("oklab").resize(scale).extract_bands(0, n=3) rgbf = thumbnail.write_to_memory() That'll stream the source image and make a RGBRGBRGB memory buffer of single precision floats. You could perhaps use kernel="linear" and avoid any ringing from lanczos3. I think I would downsample in a linear light space, like scRGB. Averaging there means averaging photons, which will surely be better than OKLab. Maybe switch to OKLab for clustering. Though of course I've not tested it.