class OpenCVColor::Cluster

Public Class Methods

new(color) click to toggle source
# File lib/opencv-color.rb, line 27
def initialize(color)
  @h, @s, @v = [], [], []
  @hs = 0
  self << color
end

Public Instance Methods

<<(color) click to toggle source
# File lib/opencv-color.rb, line 33
def <<(color)
  @h << color[0]
  @s << color[1]
  @v << color[2]
  @hs += color[0]
end
center() click to toggle source
# File lib/opencv-color.rb, line 44
def center
  @hs / @h.size
end
color_range() click to toggle source
# 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() click to toggle source
# File lib/opencv-color.rb, line 48
def colors
  [@h, @s, @v]
end
distance(color) click to toggle source
# File lib/opencv-color.rb, line 40
def distance(color)
  (center - color[0]).abs
end
max_value(i) click to toggle source
# File lib/opencv-color.rb, line 66
def max_value(i)
  # H => 0
  i == 0 ? 179.0 : 255.0
end