Project

camalian

0.02
No commit activity in last 3 years
No release in over 3 years
Library used to deal with colors and images
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.14, >= 5.14.2
~> 13.0, >= 13.0.1

Runtime

~> 1.3, >= 1.3.14
 Project Readme

Camalian

Gem Version Ruby Maintainability

Ruby gem to extract color palettes from images and play with their saturation

Installation

Add this line to your application's Gemfile:

gem 'camalian', '~> 0.2.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install camalian

Usage

image = Camalian::load('file_path')
colors = image.prominent_colors(15)
colors = colors.sort_similar_colors
colors.light_colors(0, 40)

You can find a working example with detail explanation and reference code here on this link. Here we will build a functional color based image search engine in Ruby on Rails.

NOTE: Since its a compute intensive operation so for production use its suggested to use under a background job and not within a request/response cycle.

Quantization Algorithms

Currently following algorithms are implemented.

Histogram

Its a most common algorithm for color quantization and used different bucket technique to group the colors together. You can read more about this technique here. It can be accessed by Camalian::QUANTIZATION_HISTOGRAM constant. This is used as default method as well.

K Means

This algorithm uses color distancing in RGB space to group the similar colors. You can learn more about this technique here. It can be accessed by Camalian::QUANTIZATION_K_MEANS constant.

Median Cut

This algorithm uses color highest color range to determine the median and split colors to groups. The output consists of average color of such color groups. Since these algorithm don't use actual colors and instead average, so you will may not exact matching pixel in the image. This algorithm is nice to be used with image compression, where similarity and compression is important than having same pixel colors. You can learn more about this technique here . It can be accessed by Camalian::QUANTIZATION_MEDIAN_CUT constant.

You can set default quantization method globally as:

Camalian.options[:quantization] = Camalian::QUANTIZATION_K_MEANS

or you can set at the time of extracting colors by.

image = Camalian::load('file_path')
colors = image.prominent_colors(15, quantization: Camalian::QUANTIZATION_K_MEANS)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request