Class: ImageCompare::Modes::Grayscale
- Inherits:
-
Base
- Object
- Base
- ImageCompare::Modes::Grayscale
show all
- Defined in:
- lib/image_compare/modes/grayscale.rb
Constant Summary
collapse
- DEFAULT_TOLERANCE =
16
Instance Attribute Summary collapse
Attributes inherited from Base
#bounds, #exclude_rect, #include_rect, #lower_threshold, #result, #threshold
Instance Method Summary
collapse
-
#background(bg) ⇒ Object
-
#color_similar?(a, b) ⇒ Boolean
-
#create_diff_image(_bg, diff_image) ⇒ Object
-
#initialize(**options) ⇒ Grayscale
constructor
A new instance of Grayscale.
-
#pixels_diff(d, _a, _b, x, y) ⇒ Object
-
#pixels_equal?(a, b) ⇒ Boolean
-
#update_result(a, b, x, y) ⇒ Object
Methods inherited from Base
#area, #compare, #diff, #score, #update_bounds
#blue, #brightness, #green, #orange, #red, #transparent, #yellow
Constructor Details
#initialize(**options) ⇒ Grayscale
Returns a new instance of Grayscale.
12
13
14
15
|
# File 'lib/image_compare/modes/grayscale.rb', line 12
def initialize(**options)
@tolerance = options.delete(:tolerance) || DEFAULT_TOLERANCE
super(**options)
end
|
Instance Attribute Details
#tolerance ⇒ Object
Returns the value of attribute tolerance.
10
11
12
|
# File 'lib/image_compare/modes/grayscale.rb', line 10
def tolerance
@tolerance
end
|
Instance Method Details
#background(bg) ⇒ Object
28
29
30
|
# File 'lib/image_compare/modes/grayscale.rb', line 28
def background(bg)
bg.to_grayscale
end
|
#color_similar?(a, b) ⇒ Boolean
40
41
42
43
|
# File 'lib/image_compare/modes/grayscale.rb', line 40
def color_similar?(a, b)
d = (a - b).abs
d <= tolerance
end
|
#create_diff_image(_bg, diff_image) ⇒ Object
36
37
38
|
# File 'lib/image_compare/modes/grayscale.rb', line 36
def create_diff_image(_bg, diff_image)
diff_image
end
|
#pixels_diff(d, _a, _b, x, y) ⇒ Object
32
33
34
|
# File 'lib/image_compare/modes/grayscale.rb', line 32
def pixels_diff(d, _a, _b, x, y)
d[x, y] = rgb(255, 0, 0)
end
|
#pixels_equal?(a, b) ⇒ Boolean
17
18
19
20
21
|
# File 'lib/image_compare/modes/grayscale.rb', line 17
def pixels_equal?(a, b)
alpha = color_similar?(a(a), a(b))
brightness = color_similar?(brightness(a), brightness(b))
brightness && alpha
end
|
#update_result(a, b, x, y) ⇒ Object
23
24
25
26
|
# File 'lib/image_compare/modes/grayscale.rb', line 23
def update_result(a, b, x, y)
super
@result.diff << [a, b, x, y]
end
|