class Imatcher::Modes::Delta

Compare pixels using Delta E distance.

Attributes

tolerance[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/imatcher/modes/delta.rb, line 9
def initialize(options)
  @tolerance = options.delete(:tolerance) || 0.01
  @delta_score = 0.0
  super(options)
end

Private Instance Methods

background(bg) click to toggle source
# File lib/imatcher/modes/delta.rb, line 29
def background(bg)
  Image.new(bg.width, bg.height, WHITE).with_alpha(0)
end
create_diff_image(bg, diff_image) click to toggle source
# File lib/imatcher/modes/delta.rb, line 41
def create_diff_image(bg, diff_image)
  bg.to_grayscale.compose!(diff_image, 0, 0)
end
euclid(a, b) click to toggle source
# File lib/imatcher/modes/delta.rb, line 33
def euclid(a, b)
  Math.sqrt(
    (r(a) - r(b))**2 +
    (g(a) - g(b))**2 +
    (b(a) - b(b))**2
  )
end
pixels_diff(d, *_args, x, y, a) click to toggle source
# File lib/imatcher/modes/delta.rb, line 45
def pixels_diff(d, *_args, x, y, a)
  d[x, y] = rgba(MAX, 0, 0, (a * MAX).round)
end
pixels_equal?(a, b) click to toggle source
# File lib/imatcher/modes/delta.rb, line 17
def pixels_equal?(a, b)
  a == b
end
score() click to toggle source
# File lib/imatcher/modes/delta.rb, line 49
def score
  @delta_score / area
end
update_result(a, b, x, y) click to toggle source
Calls superclass method
# File lib/imatcher/modes/delta.rb, line 21
def update_result(a, b, x, y)
  d = euclid(a, b) / (MAX * Math.sqrt(3))
  return if d <= tolerance
  @result.diff << [a, b, x, y, d]
  @delta_score += d
  super
end