dhash-vips 0.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6dbc3028fb3c5b856d3d3836e9829f0fe0194104
4
+ data.tar.gz: 80426a3be479450729ea1e2d8eb1fc2cec0659ea
5
+ SHA512:
6
+ metadata.gz: 28d979ed682861592c339144a71c4a54561cbf6cf4818cd5336425449367551b044e88b1eb3ddda303aa58e8cc23ccb30e7a041448551f2b019e385551a92635
7
+ data.tar.gz: 306cbfb280c9cfb594990933904ab2f1bc116cb2aefc7b3039cf7bbe8140aa6540511bb317c43d7b8174848809969c3888656a103b9a364f54dc7f8fece7a0ba
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dhash.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nakilon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # About
2
+
3
+ dHash is for measuring the similarity of two images.
4
+
5
+ Read "Kind of Like That" blog post (21 January 2013): http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
6
+
7
+ It does not automatically detect very shifted crops and rotated images but you may make a wrapper that would call the comparison function iteratively.
8
+
9
+ This implementation is powered by Vips and was forked from https://github.com/maccman/dhash (by Alex MacCaw) that was using ImageMagick.
10
+
11
+ # Installation
12
+
13
+ gem install dhash-vips
14
+
15
+ # Usage
16
+
17
+ hash1 = DhashVips.calculate "face-high.jpg"
18
+ hash2 = DhashVips.calculate "face-low.jpg"
19
+
20
+ if 10 > DhashVips.hamming(hash1, hash2)
21
+ puts "Images are very similar"
22
+ else
23
+ puts "No match"
24
+ end
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => %w{ spec }
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.verbose = false
8
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "dhash-vips"
3
+ spec.version = (require_relative "lib/dhash-vips/version"; DhashVips::VERSION)
4
+ spec.author = "Victor Maslov"
5
+ spec.email = "nakilon@gmail.com"
6
+ spec.summary = "dHash powered by Vips"
7
+ spec.homepage = "https://github.com/nakilon/dhash-vips"
8
+ spec.license = "MIT"
9
+
10
+ spec.files = `git ls-files -z`.split("\x0") - ["spec"]
11
+ spec.test_files = ["spec"]
12
+ spec.require_path = "lib"
13
+
14
+ spec.add_dependency "vips"
15
+
16
+ spec.add_development_dependency "dhash"
17
+
18
+ spec.add_development_dependency "rake"
19
+ spec.add_development_dependency "rspec"
20
+ end
@@ -0,0 +1,28 @@
1
+ require_relative "dhash-vips/version"
2
+ require "vips"
3
+
4
+ module DhashVips
5
+ extend self
6
+
7
+ def hamming a, b
8
+ (a^b).to_s(2).count('1')
9
+ end
10
+
11
+ def calculate file, hash_size = 8
12
+ image = Vips::Image.new_from_file file
13
+ image = image.resize((hash_size + 1).fdiv(image.width), vscale: hash_size.fdiv(image.height)).colourspace "b-w"
14
+
15
+ difference = []
16
+
17
+ hash_size.times do |row|
18
+ hash_size.times do |col|
19
+ pixel_left = image.getpoint(col, row).first
20
+ pixel_right = image.getpoint(col + 1, row).first
21
+ difference << (pixel_left > pixel_right)
22
+ end
23
+ end
24
+
25
+ difference.map{ |d| d ? 1 : 0 }.join("").to_i(2)
26
+ end
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module DhashVips
2
+ VERSION = "0.0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require "dhash-vips"
2
+
3
+ describe DhashVips do
4
+ it 'should have similar hashes for low/high of same image' do
5
+ hash1 = DhashVips.calculate(File.expand_path('../images/face-high.jpg', __FILE__))
6
+ hash2 = DhashVips.calculate(File.expand_path('../images/face-low.jpg', __FILE__))
7
+
8
+ expect(DhashVips.hamming(hash1, hash2)).to be < 3
9
+ end
10
+
11
+ it 'should have similar hashes for similar images' do
12
+ hash1 = DhashVips.calculate(File.expand_path('../images/face-high.jpg', __FILE__))
13
+ hash2 = DhashVips.calculate(File.expand_path('../images/face-with-nose.jpg', __FILE__))
14
+
15
+ expect(DhashVips.hamming(hash1, hash2)).to be < 5
16
+ end
17
+
18
+ it 'should have identical hashes for identical images' do
19
+ hash1 = DhashVips.calculate(File.expand_path('../images/face-high.jpg', __FILE__))
20
+ hash2 = DhashVips.calculate(File.expand_path('../images/face-high.jpg', __FILE__))
21
+
22
+ expect(DhashVips.hamming(hash1, hash2)).to be == 0
23
+ end
24
+ end
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dhash-vips
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Maslov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dhash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: nakilon@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - dhash.gemspec
81
+ - lib/dhash-vips.rb
82
+ - lib/dhash-vips/version.rb
83
+ - spec/_spec.rb
84
+ - spec/images/face-high.jpg
85
+ - spec/images/face-low.jpg
86
+ - spec/images/face-with-nose.jpg
87
+ homepage: https://github.com/nakilon/dhash-vips
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.14.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: dHash powered by Vips
111
+ test_files: []