Class: ImageCompare::Modes::Color
- Includes:
- ColorMethods
- Defined in:
- lib/image_compare/modes/color.rb
Constant Summary collapse
- DEFAULT_TOLERANCE =
16
Instance Attribute Summary collapse
-
#tolerance ⇒ Object
readonly
Returns the value of attribute tolerance.
Attributes inherited from Base
#bounds, #exclude_rect, #include_rect, #lower_threshold, #result, #threshold
Instance Method Summary collapse
- #area_in_exclude_rect? ⇒ Boolean
- #color_similar?(a, b) ⇒ Boolean
- #diff(bg, diff) ⇒ Object
-
#initialize(**options) ⇒ Color
constructor
A new instance of Color.
- #pixels_equal?(a, b) ⇒ Boolean
- #update_result(a, b, x, y) ⇒ Object
Methods included from ColorMethods
#blue, #brightness, #green, #orange, #red, #transparent, #yellow
Methods inherited from Base
#area, #compare, #score, #update_bounds
Constructor Details
#initialize(**options) ⇒ Color
Returns a new instance of Color.
14 15 16 17 |
# File 'lib/image_compare/modes/color.rb', line 14 def initialize(**) @tolerance = .delete(:tolerance) || DEFAULT_TOLERANCE super(**) end |
Instance Attribute Details
#tolerance ⇒ Object (readonly)
Returns the value of attribute tolerance.
12 13 14 |
# File 'lib/image_compare/modes/color.rb', line 12 def tolerance @tolerance end |
Instance Method Details
#area_in_exclude_rect? ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/image_compare/modes/color.rb', line 27 def area_in_exclude_rect? return false if exclude_rect.nil? diff_area = { left: bounds.bounds[0], top: bounds.bounds[1], right: bounds.bounds[2], bot: bounds.bounds[3] } exclude_area = { left: exclude_rect.bounds[0], top: exclude_rect.bounds[1], right: exclude_rect.bounds[2], bot: exclude_rect.bounds[3] } diff_area[:left] <= exclude_area[:left] && diff_area[:top] <= exclude_area[:top] && diff_area[:right] >= exclude_area[:right] && diff_area[:bot] >= exclude_area[:bot] end |
#color_similar?(a, b) ⇒ Boolean
61 62 63 64 |
# File 'lib/image_compare/modes/color.rb', line 61 def color_similar?(a, b) d = (a - b).abs d <= tolerance end |
#diff(bg, diff) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/image_compare/modes/color.rb', line 19 def diff(bg, diff) diff_image = bg.highlight_rectangle(exclude_rect, :blue) return diff_image if self.result.match? diff_image.highlight_rectangle(bounds) unless area_in_exclude_rect? end |
#pixels_equal?(a, b) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/image_compare/modes/color.rb', line 50 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
56 57 58 59 |
# File 'lib/image_compare/modes/color.rb', line 56 def update_result(a, b, x, y) super @result.diff << [a, b, x, y] end |