Color decomposition
A quadtree color decomposition algorithm that uses the CIELAB color space and the CIEDE2000 color-difference formula.
The generated quadtree structure contains the leaves that represent the highest node levels containing a perceptually similar color for a given area.
Prerequisite
This gem requires an installation of
ImageMagick version 6
.
Installation
Installing can be done by adding the following line to an application's Gemfile:
gem 'color_decomposition'
and then executing:
$ bundle
Or just install it yourself using:
$ gem install color_decomposition
Usage
Generating the actual quadtree simply requires calling the quadtree
method. This
method takes 2 parameters. The first being the path to the image and the second being
the color similarity level that the CIEDE2000 formula should use. The larger this value,
the more color loss will be permitted. A larger value will therefore allow the creation
of larger leaf nodes at the cost of color accuracy.
When comparing 2 colors, a CIEDE2000 value of <= 1
will generally mean that the
difference between them will not be perceivable to the human eye.
require 'color_decomposition'
quadtree = ColorDecomposition.quadtree('ruby.png', 1)
This will return a Node object containing the following accessible instance variables: rgb
, lab
, rect
and child_nodes
. However, only the leaf
nodes will have the RGB and CIELAB color values set.
The color conversions and CIEDE2000 calculation can also be used on their own.
require 'color_decomposition'
include ColorDecomposition
color1 = Color.new(r: 255, g: 120, b: 60)
puts color1.xyz # {:x=>48.77208180663368, :y=>35.01918603060906, :z=>8.46377233268254}
puts color1.lab # {:l=>65.76360001472788, :a=>47.86642591164642, :b=>55.61626679147632}
color2 = Color.new(r: 80, g: 49, b: 220)
puts Comparator.ciede2000(color1.lab, color2.lab) # 57.24131929494836