image_compare 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -17
- data/lib/image_compare/modes/base.rb +1 -1
- data/lib/image_compare/rectangle.rb +3 -1
- data/lib/image_compare/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9172a89fc7bd3779f58bf4291d045db2e9de6ce8e1d17d7eed9be6970c6faed9
|
4
|
+
data.tar.gz: f3d1a90a07c4d728ea51c2effd424d9a32b4567b53b59119a996637defebc4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8a0fcbd0668b614592b65972d1326a7a2f2853da2a133150fd6d5d0e8153a46f7d986033cec071d6df6b6cdd6c5b0c7950cd76b07494dc6bd8e240ee4d928b3
|
7
|
+
data.tar.gz: 8c81cf6accfeb98d780ff3ed724834b5816c0d245186086d9b075e77f56a8f29f9d52d20fa4d01210bc5a8ddd36dfb7e7694ffc9e8024fc809e4a10b31437a42
|
data/README.md
CHANGED
@@ -33,8 +33,8 @@ ImageCompare supports different ways (_modes_) of comparing images.
|
|
33
33
|
|
34
34
|
Source images used in examples:
|
35
35
|
|
36
|
-
<img src='
|
37
|
-
<img src='
|
36
|
+
<img alt='a.png' src='spec/fixtures/a.png' />
|
37
|
+
<img alt='b.png' src='spec/fixtures/b.png' />
|
38
38
|
|
39
39
|
### Color
|
40
40
|
|
@@ -42,14 +42,14 @@ Compare pixels, resulting score is a ratio of unequal pixels (with respect to pr
|
|
42
42
|
|
43
43
|
Resulting diff contains version of the first image with different pixels highlighted in red and red bounding box.
|
44
44
|
|
45
|
-
<img src='
|
45
|
+
<img alt='color_diff' src='spec/fixtures/color_diff.png' />
|
46
46
|
|
47
47
|
### Base (RGB) mode
|
48
48
|
|
49
49
|
Compare pixels by values, resulting score is a ratio of unequal pixels.
|
50
50
|
Resulting diff represents per-channel difference.
|
51
51
|
|
52
|
-
<img src='
|
52
|
+
<img alt='rgb_diff.png' src='spec/fixtures/rgb_diff.png' width='480' />
|
53
53
|
|
54
54
|
### Grayscale mode
|
55
55
|
|
@@ -57,14 +57,14 @@ Compare pixels as grayscale (by brightness and alpha), resulting score is a rati
|
|
57
57
|
|
58
58
|
Resulting diff contains grayscale version of the first image with different pixels highlighted in red and red bounding box.
|
59
59
|
|
60
|
-
<img src='
|
60
|
+
<img alt='grayscale_diff.png' src='spec/fixtures/grayscale_diff.png' width='480' />
|
61
61
|
|
62
62
|
### Delta
|
63
63
|
|
64
64
|
Compare pixels using [Delta E](https://en.wikipedia.org/wiki/Color_difference) distance.
|
65
65
|
Resulting diff contains grayscale version of the first image with different pixels highlighted in red (with respect to diff score).
|
66
66
|
|
67
|
-
<img src='
|
67
|
+
<img alt='delta_diff.png' src='spec/fixtures/delta_diff.png' width='480' />
|
68
68
|
|
69
69
|
## Usage
|
70
70
|
|
@@ -91,43 +91,47 @@ cmp.lower_threshold #=> 0.01
|
|
91
91
|
cmp = ImageCompare::Matcher.new mode: :grayscale, tolerance: 0
|
92
92
|
cmp.mode #=> ImageCompare::Modes::Grayscale
|
93
93
|
|
94
|
-
res = cmp.compare(
|
94
|
+
res = cmp.compare('path/image1.png', 'path/image2.png')
|
95
95
|
res #=> ImageCompare::Result
|
96
96
|
res.match? #=> true
|
97
97
|
res.score #=> 0.0
|
98
98
|
|
99
99
|
# Return diff image object
|
100
100
|
res.difference_image #=> ImageCompare::Image
|
101
|
-
res.difference_image.save(
|
101
|
+
res.difference_image.save(result)
|
102
102
|
|
103
103
|
# without explicit matcher
|
104
|
-
res = ImageCompare.compare(
|
104
|
+
res = ImageCompare.compare('path/image1.png', 'path/image2.png', options)
|
105
|
+
res.match? #=> true
|
106
|
+
res.score #=> 0.0
|
105
107
|
|
106
108
|
# equals to
|
107
|
-
res = ImageCompare::Matcher.new(options).compare(
|
109
|
+
res = ImageCompare::Matcher.new(options).compare('my_images_path/image1.png', 'my_images_path/image2.png')
|
110
|
+
res.match? #=> true
|
111
|
+
res.score #=> 0.0
|
108
112
|
```
|
109
113
|
|
110
114
|
## Excluding rectangle
|
111
115
|
|
112
|
-
<img src='
|
113
|
-
<img src='
|
116
|
+
<img alt='a.png' src='spec/fixtures/a.png' />
|
117
|
+
<img alt='a1.png' src='spec/fixtures/a1.png' />
|
114
118
|
|
115
119
|
You can exclude rectangle from comparing by passing `:exclude_rect` to `compare`.
|
116
120
|
E.g., if `path_1` and `path_2` contain images above
|
117
121
|
```ruby
|
118
|
-
ImageCompare.compare(
|
122
|
+
ImageCompare.compare('path/image1.png', 'path/image2.png', exclude_rect: [200, 150, 275, 200]).match? # => true
|
119
123
|
|
120
124
|
# or
|
121
125
|
|
122
126
|
cmp = ImageCompare::Matcher.new exclude_rect: [200, 150, 275, 200]
|
123
|
-
res = cmp.compare(
|
127
|
+
res = cmp.compare('path/image1.png', 'path/image2.png')
|
124
128
|
res #=> ImageCompare::Result
|
125
129
|
res.match? #=> true
|
126
130
|
res.score #=> 0.0
|
127
131
|
|
128
132
|
# Return diff image object
|
129
133
|
res.difference_image #=> ImageCompare::Image
|
130
|
-
res.difference_image.save(
|
134
|
+
res.difference_image.save('path/diff.png')
|
131
135
|
```
|
132
136
|
`[200, 150, 275, 200]` is array of two vertices of rectangle -- (200, 150) is left-top vertex and (275, 200) is right-bottom.
|
133
137
|
|
@@ -162,8 +166,8 @@ end
|
|
162
166
|
my_element = page.find('#my_element').rect_area
|
163
167
|
|
164
168
|
cmp = ImageCompare::Matcher.new exclude_rect: my_element.rect_area
|
165
|
-
res = cmp.compare(
|
166
|
-
res.difference_image.save(
|
169
|
+
res = cmp.compare('path/image1.png', 'path/image2.png')
|
170
|
+
res.difference_image.save('path/diff.png')
|
167
171
|
|
168
172
|
expect(res.match?).to eq(true)
|
169
173
|
```
|
@@ -22,8 +22,8 @@ module ImageCompare
|
|
22
22
|
@bounds = Rectangle.new(*include_rect.bounds)
|
23
23
|
|
24
24
|
b.compare_each_pixel(a, area: include_rect) do |b_pixel, a_pixel, x, y|
|
25
|
-
next if pixels_equal?(b_pixel, a_pixel)
|
26
25
|
next if !exclude_rect.nil? && exclude_rect.contains_point?(x, y)
|
26
|
+
next if pixels_equal?(b_pixel, a_pixel)
|
27
27
|
update_result(b_pixel, a_pixel, x, y)
|
28
28
|
end
|
29
29
|
|
@@ -27,7 +27,9 @@ module ImageCompare
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def contains_point?(x, y)
|
30
|
-
x
|
30
|
+
(x >= left && y >= top && x <= right && y <= bot) ||
|
31
|
+
(x <= right && y <= top && x >= left && y >= bot) ||
|
32
|
+
(x.between?(right, left) && y.between?(bot, top))
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_compare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cristianofmc
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chunky_png
|