Class: OpenCVColor::Cluster
- Inherits:
-
Object
- Object
- OpenCVColor::Cluster
- Defined in:
- lib/opencv-color.rb
Instance Method Summary collapse
- #<<(color) ⇒ Object
- #center ⇒ Object
- #color_range ⇒ Object
- #colors ⇒ Object
- #distance(color) ⇒ Object
-
#initialize(color) ⇒ Cluster
constructor
A new instance of Cluster.
- #max_value(i) ⇒ Object
Constructor Details
#initialize(color) ⇒ Cluster
Returns a new instance of Cluster.
27 28 29 30 31 |
# File 'lib/opencv-color.rb', line 27 def initialize(color) @h, @s, @v = [], [], [] @hs = 0 self << color end |
Instance Method Details
#<<(color) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/opencv-color.rb', line 33 def <<(color) @h << color[0] @s << color[1] @v << color[2] @hs += color[0] end |
#center ⇒ Object
44 45 46 |
# File 'lib/opencv-color.rb', line 44 def center @hs / @h.size end |
#color_range ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/opencv-color.rb', line 52 def color_range memo = {low: [], high: [], mean: [], sd: []} colors.map(&:to_scale).each_with_index do |d, index| sd = d.sd mean = d.mean memo[:low] << ([mean - 3 * sd, 0.0].max).floor memo[:high] << ([mean + 3 * sd, max_value(index)].min).ceil memo[:mean] << mean memo[:sd] << sd end memo end |
#colors ⇒ Object
48 49 50 |
# File 'lib/opencv-color.rb', line 48 def colors [@h, @s, @v] end |
#distance(color) ⇒ Object
40 41 42 |
# File 'lib/opencv-color.rb', line 40 def distance(color) (center - color[0]).abs end |
#max_value(i) ⇒ Object
66 67 68 69 |
# File 'lib/opencv-color.rb', line 66 def max_value(i) # H => 0 i == 0 ? 179.0 : 255.0 end |