Module: Huespace
- Defined in:
- lib/huespace.rb,
lib/huespace/median_cut.rb
Defined Under Namespace
Classes: MedianCut
Class Method Summary collapse
-
.get_dominant_color(image_source) ⇒ Object
Returns the dominant color.
-
.get_most_colorful_color(image_source) ⇒ Object
Returns most colorful color This is achieved by sorting the palette using the following formula: (max + min) * (max - min)) / max max and min represent one of the rgb values More about this here: changingminds.org/explanations/perception/visual/colourfulness.htm.
-
.get_palette(image_source, n_colors) ⇒ Object
Returns a palette of representative colors.
Class Method Details
.get_dominant_color(image_source) ⇒ Object
Returns the dominant color
27 28 29 30 31 |
# File 'lib/huespace.rb', line 27 def Huespace.get_dominant_color(image_source) colors = Huespace.get_palette(image_source, 5) return colors[0] end |
.get_most_colorful_color(image_source) ⇒ Object
Returns most colorful color This is achieved by sorting the palette using the following formula: (max + min) * (max - min)) / max max and min represent one of the rgb values More about this here: changingminds.org/explanations/perception/visual/colourfulness.htm
20 21 22 23 24 |
# File 'lib/huespace.rb', line 20 def Huespace.get_most_colorful_color(image_source) colors = Huespace.get_palette(image_source, 6) return colors.sort_by { |color| ((color.max + color.min) * (color.max - color.min)) / color.max }.last() end |
.get_palette(image_source, n_colors) ⇒ Object
Returns a palette of representative colors
8 9 10 11 12 13 |
# File 'lib/huespace.rb', line 8 def Huespace.get_palette(image_source, n_colors) pixels = Huespace.load_image(image_source) sampled_pixels, hist = Huespace.sample_pixels(pixels) Huespace::MedianCut.process(sampled_pixels, n_colors, hist) end |