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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0720bdefa1875125c9b3a70b9301cfcc09da69e9c3332f583fa287ee26bea23a
4
- data.tar.gz: a69b1cfae60e5ef147d24eb9ec1778de52dc3d111f5694df585510a7e34ccfca
3
+ metadata.gz: a265a3a6340812f32f4f438182a263e5f51428b75fd11a2085700fb455c9a4e4
4
+ data.tar.gz: f842ba4e06f8731225956314fca77544615bd9b021a37e2bd2a6fbd81ea2a07c
5
5
  SHA512:
6
- metadata.gz: c32e15baa91fc1a7d88a50a92be1806acaac1d335d5347312d15aa11d14b0c7a9c271f91ba5bac8af6efe3c30f885cf35a27cd6eadcd9cbb1b8afceb8165b903
7
- data.tar.gz: aa03da6d1d3cc0e72d13f7520ec2ff881d61d61648b4847dcb875b06127d202c563cc5a23bcbee292fd47395967ae06e3bd49287836bfc168a9c409d4b05c71c
6
+ metadata.gz: 749712981d31f8b49f99a43c086e3b77e0900a0f4a41de15ae5a2c8a676ab8e73216ee5c61778aa49cc454344a0d8dbd89ba164d3b0b748de194280fe696bf71
7
+ data.tar.gz: 2ce49467b2110c9bf0ab57bf6e543726f2c3f57b3eabfc8320e9c9fb90f5c9f7dc1a5891dae1160a36d50ce07de6514760bb049ee74f3d47b238d06f11d1d4b9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixel_matcher (0.0.1)
4
+ pixel_matcher (0.0.2)
5
5
  rmagick (~> 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # PixelMatcher
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pixel_matcher`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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/[USERNAME]/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.
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/[USERNAME]/pixel_matcher/blob/master/CODE_OF_CONDUCT.md).
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
- class PixelMatcher::DiffImage < Magick::Image
4
- def initialize(path1, path2)
5
- img1 = [].tap do |arr|
6
- Magick::Image.read(path1).first.each_pixel do |pixel, c ,r|
7
- arr << [pixel, c, r]
8
- end
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
- img2 = [].tap do |arr|
12
- Magick::Image.read(path2).first.each_pixel do |pixel, c ,r|
13
- arr << [pixel, c, r]
14
- end
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
- super(img1.last[1], img1.last[2])
24
+ private
18
25
 
19
- img1.zip(img2) do |i1, i2|
20
- if (i1[0] <=> i2[0]) != 0
21
- self.store_pixels(i1[1], i1[2], 1, 1, [i1[0]])
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
- def export(output_path)
27
- self.write(output_path)
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
@@ -1,3 +1,3 @@
1
1
  module PixelMatcher
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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.1
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: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2020-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick