pixel_matcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -6
- data/lib/pixel_matcher/diff_image.rb +40 -19
- data/lib/pixel_matcher/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: a265a3a6340812f32f4f438182a263e5f51428b75fd11a2085700fb455c9a4e4
|
4
|
+
data.tar.gz: f842ba4e06f8731225956314fca77544615bd9b021a37e2bd2a6fbd81ea2a07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 749712981d31f8b49f99a43c086e3b77e0900a0f4a41de15ae5a2c8a676ab8e73216ee5c61778aa49cc454344a0d8dbd89ba164d3b0b748de194280fe696bf71
|
7
|
+
data.tar.gz: 2ce49467b2110c9bf0ab57bf6e543726f2c3f57b3eabfc8320e9c9fb90f5c9f7dc1a5891dae1160a36d50ce07de6514760bb049ee74f3d47b238d06f11d1d4b9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# PixelMatcher
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Library to compare images and generate difference image files
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,14 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
```ruby
|
24
|
+
require 'pixel_matcher
|
25
|
+
|
26
|
+
diff = PixelMatcher::DiffImage('img1.png', 'img2.png')
|
27
|
+
diff.export_diff('diff.png')
|
28
|
+
diff.export_gray_scale('gray_scale.png')
|
29
|
+
```
|
30
|
+
|
26
31
|
|
27
32
|
## Development
|
28
33
|
|
@@ -32,7 +37,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
37
|
|
33
38
|
## Contributing
|
34
39
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ksk001100/pixel_matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
41
|
|
37
42
|
## License
|
38
43
|
|
@@ -40,4 +45,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
45
|
|
41
46
|
## Code of Conduct
|
42
47
|
|
43
|
-
Everyone interacting in the PixelMatcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
48
|
+
Everyone interacting in the PixelMatcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ksk001100/pixel_matcher/blob/master/CODE_OF_CONDUCT.md).
|
@@ -1,29 +1,50 @@
|
|
1
1
|
require 'rmagick'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Magick::Image.read(path1).first
|
7
|
-
|
8
|
-
|
3
|
+
module PixelMatcher
|
4
|
+
class DiffImage < Magick::Image
|
5
|
+
def initialize(path1, path2)
|
6
|
+
@img1 = Magick::Image.read(path1).first
|
7
|
+
@img2 = Magick::Image.read(path2).first
|
8
|
+
@gray_scale = @img1.clone.quantize(256, Magick::GRAYColorspace)
|
9
|
+
@diff = Magick::Image.new(@img1.columns, @img1.rows)
|
9
10
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
|
12
|
+
def export_diff(output_path)
|
13
|
+
store_diff
|
14
|
+
@diff.write(output_path)
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def export_gray_scale(output_path)
|
19
|
+
store_gray_scale_diff
|
20
|
+
@gray_scale.write(output_path)
|
21
|
+
self
|
15
22
|
end
|
16
23
|
|
17
|
-
|
24
|
+
private
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
def store_diff
|
27
|
+
@img1.columns.times do |i|
|
28
|
+
@img1.rows.times do |j|
|
29
|
+
@diff.store_pixels(i, j, 1, 1, [@img1.pixel_color(i, j)]) unless eq_pixel?(@img1, @img2, i, j)
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
|
-
end
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
def store_gray_scale_diff
|
35
|
+
@img1.columns.times do |i|
|
36
|
+
@img1.rows.times do |j|
|
37
|
+
@gray_scale.store_pixels(i, j, 1, 1, [@img1.pixel_color(i, j)]) unless eq_pixel?(@img1, @img2, i, j)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
28
41
|
end
|
29
|
-
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def image_array(img)
|
45
|
+
img.export_pixels.each_slice(3).each_slice(img.columns).to_a
|
46
|
+
end
|
47
|
+
|
48
|
+
def eq_pixel?(img1, img2, i, j)
|
49
|
+
img1.pixel_color(i, j) == img2.pixel_color(i, j)
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixel_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksk001100
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|