Top Level Namespace

Includes:
Grayphash

Defined Under Namespace

Modules: Grayphash

Instance Method Summary collapse

Instance Method Details

#max_metric(hist1, hist2) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'ext/grayphash/histo.rb', line 9

def max_metric hist1, hist2
  h1 = hist1.each_with_index.sort.reverse[$start,$degree]
  h2 = hist2.each_with_index.sort.reverse[$start,$degree]
  #pp h2
  result = 0
  [0, $degree-1].each do |i|
  #[0, 255].each do |i|
    #result += (hist1[i] - hist2[i]).abs.to_f # / (hist1[i] + hist2[i] + 1)
    result += (h1[i][1] - h2[i][1]).abs.to_f / (h1[i][1] + h2[i][1] + 1)  # это даёт хороший результат. Если расстояние меньше 0,02, то скорее всего мы попали в нужную картинку.
  end
  return result
end

#progress_max_metric(hist1, hist2) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/grayphash/histo.rb', line 22

def progress_max_metric hist1, hist2
  h1 = hist1.each_with_index.sort.reverse[$start,$degree]
  h2 = hist2.each_with_index.sort.reverse[$start,$degree]
  #pp h2
  result = 0
  k = 1.0
  [0, $degree-1].each do |i|
    result += k.to_f * (h1[i][1] - h2[i][1]).abs.to_f / (h1[i][1] + h2[i][1] + 1)
    k /= 2
  end
  return result
end