Class: Kolors::DominantColors
- Inherits:
-
Object
- Object
- Kolors::DominantColors
- Defined in:
- lib/kolors/dominant_colors.rb
Instance Attribute Summary collapse
-
#src_image_path ⇒ Object
Returns the value of attribute src_image_path.
Instance Method Summary collapse
-
#initialize(src_image_path) ⇒ DominantColors
constructor
A new instance of DominantColors.
- #kmeans_result ⇒ Object
- #to_facets ⇒ Object
- #to_lab ⇒ Object
Constructor Details
#initialize(src_image_path) ⇒ DominantColors
Returns a new instance of DominantColors.
5 6 7 |
# File 'lib/kolors/dominant_colors.rb', line 5 def initialize(src_image_path) @src_image_path = src_image_path end |
Instance Attribute Details
#src_image_path ⇒ Object
Returns the value of attribute src_image_path.
3 4 5 |
# File 'lib/kolors/dominant_colors.rb', line 3 def src_image_path @src_image_path end |
Instance Method Details
#kmeans_result ⇒ Object
21 22 23 |
# File 'lib/kolors/dominant_colors.rb', line 21 def kmeans_result @kmeans_result ||= extract_colors_from_image end |
#to_facets ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/kolors/dominant_colors.rb', line 9 def to_facets # Map each centroid to key_colors facets = to_lab.each_with_index.collect do |color,index| { key_colors[key_colors.keys.sort_by {|c| dist(color, c) }.first] => kmeans_result.clusters[index].data_items.size} end percentize(group_hashes_sum_values(facets)) end |