No commit activity in last 3 years
No release in over 3 years
Create a quadtree by decomposing images by color using CIELAB.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 12.0
~> 3.1

Runtime

~> 2.16
 Project Readme

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

Resources