dhash-vips 0.1.1.5 → 0.2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +6 -5
- data/common.rb +3 -13
- data/dhash-vips.gemspec +1 -1
- data/extconf.rb +3 -1
- data/lib/dhash-vips.rb +38 -31
- data/test.rb +138 -14
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a51cdf1232968a0f4717b6a76ef15a7e4378004fabdc240e472fbaac429c22c7
|
4
|
+
data.tar.gz: e20fc002226f349de7ce4cfd2c5709cbd8198640e6b2445a572abebce3a7b85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd4d7ecb82a95361cd7a1075691a9303c80f18c4b186f37cb348c041f9787d6bdf61e34d39df3d416980aba2b680e98568743c2f1822e8df75838cea8fde3e60
|
7
|
+
data.tar.gz: 297c8b7e8662e97bd051777d2b662504ae15fcfed448bf9248fd8ef941fa320430eba48bb5ff64ad10f890d985c0d7aca337578f033dcfef031b3d52026de276
|
data/Gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
|
-
gemspec
|
3
2
|
|
4
|
-
gem "byebug", "<11.1.0" # for Ruby 2.3
|
5
3
|
gem "rake"
|
6
|
-
gem "
|
7
|
-
gem "
|
4
|
+
gem "rmagick"
|
5
|
+
gem "dhash", github: "nakilon/dhash"
|
8
6
|
gem "phamilie"
|
9
|
-
gem "dhash"
|
10
7
|
gem "get_process_mem"
|
11
8
|
gem "mll"
|
9
|
+
gem "minitest"
|
10
|
+
gem "byebug", "<11.1.0" # for Ruby 2.3
|
11
|
+
|
12
|
+
gemspec
|
data/common.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
|
-
def download_and_keep image # returns path
|
2
|
-
require "open-uri"
|
3
|
-
require "digest"
|
4
|
-
File.join(FileUtils.mkdir_p(File.expand_path "images", __dir__()).first, image).tap do |path|
|
5
|
-
open("https://storage.googleapis.com/dhash-vips.nakilon.pro/#{image}") do |link|
|
6
|
-
File.open(path, "wb") do |file|
|
7
|
-
IO.copy_stream link, file
|
8
|
-
end
|
9
|
-
end unless File.exist?(path) && Digest::MD5.file(path) == File.basename(image, ".jpg")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
1
|
def download_if_needed path
|
14
2
|
require "open-uri"
|
15
3
|
require "digest"
|
16
4
|
FileUtils.mkdir_p File.dirname path
|
17
|
-
open("
|
5
|
+
open("http://gems.nakilon.pro.storage.yandexcloud.net/dhash-vips/#{File.basename path}".tap do |url|
|
6
|
+
puts "downloading #{path} from #{url}"
|
7
|
+
end) do |link|
|
18
8
|
File.open(path, "wb"){ |file| IO.copy_stream link, file }
|
19
9
|
end unless File.exist?(path) && Digest::MD5.file(path) == File.basename(path, File.extname(path))
|
20
10
|
path
|
data/dhash-vips.gemspec
CHANGED
data/extconf.rb
CHANGED
@@ -26,8 +26,10 @@ __END__
|
|
26
26
|
|
27
27
|
to test: $ rake clean && rake install
|
28
28
|
|
29
|
+
# this unlike using rake is building to current directory
|
30
|
+
# that is vital to be able to require the native extention for benchmarking, etc.
|
29
31
|
$ ruby extconf.rb && make clean && make
|
30
|
-
$ ruby -
|
32
|
+
$ ruby -e "require 'dhash-vips'; p DHashVips::IDHash.method(:distance3).source_location" # using -r makes bundler mad
|
31
33
|
# [".../dhash-vips.rb", 32] # if LoadError
|
32
34
|
# [".../dhash-vips.rb", 52] # if native (or 42 with Ruby<2.4)
|
33
35
|
|
data/lib/dhash-vips.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "vips"
|
2
|
+
Vips.vector_set false
|
2
3
|
|
3
4
|
module DHashVips
|
4
5
|
|
@@ -9,37 +10,40 @@ module DHashVips
|
|
9
10
|
(a ^ b).to_s(2).count "1"
|
10
11
|
end
|
11
12
|
|
12
|
-
def pixelate
|
13
|
-
image = Vips::Image
|
14
|
-
|
15
|
-
image.resize((hash_size + 1).fdiv(image.width), vscale: hash_size.fdiv(image.height), kernel: kernel).colourspace("b-w")
|
13
|
+
def pixelate input, hash_size
|
14
|
+
image = if input.is_a? Vips::Image
|
15
|
+
input.thumbnail_image(hash_size + 1, height: hash_size, size: :force)
|
16
16
|
else
|
17
|
-
|
17
|
+
Vips::Image.thumbnail(input, hash_size + 1, height: hash_size, size: :force)
|
18
18
|
end
|
19
|
+
(image.has_alpha? ? image.flatten : image).colourspace("b-w")[0]
|
19
20
|
end
|
20
21
|
|
21
|
-
def calculate file, hash_size = 8
|
22
|
-
image = pixelate file, hash_size
|
23
|
-
|
22
|
+
def calculate file, hash_size = 8
|
23
|
+
image = pixelate file, hash_size
|
24
24
|
image.cast("int").conv([[1, -1]]).crop(1, 0, hash_size, hash_size).>(0)./(255).cast("uchar").to_a.join.to_i(2)
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module IDHash
|
30
|
-
extend self
|
31
30
|
|
32
|
-
def distance3_ruby a, b
|
31
|
+
def self.distance3_ruby a, b
|
33
32
|
((a ^ b) & (a | b) >> 128).to_s(2).count "1"
|
34
33
|
end
|
35
34
|
begin
|
36
35
|
require_relative "../idhash.#{Gem::Platform.local.os == "darwin" ? "bundle" : "o"}"
|
37
36
|
rescue LoadError
|
38
|
-
|
37
|
+
class << self
|
38
|
+
# https://github.com/minitest/minitest/issues/939
|
39
|
+
def distance3 a, b
|
40
|
+
distance3_ruby a, b
|
41
|
+
end
|
42
|
+
end
|
39
43
|
else
|
40
44
|
# we can't just do `defined? Bignum` because it's defined but deprecated (some internal CONST_DEPRECATED flag)
|
41
45
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4")
|
42
|
-
def distance3 a, b
|
46
|
+
def self.distance3 a, b
|
43
47
|
if a.is_a?(Bignum) && b.is_a?(Bignum)
|
44
48
|
distance3_c a, b
|
45
49
|
else
|
@@ -50,7 +54,7 @@ module DHashVips
|
|
50
54
|
# https://github.com/ruby/ruby/commit/de2f7416d2deb4166d78638a41037cb550d64484#diff-16b196bc6bfe8fba63951420f843cfb4R10
|
51
55
|
require "rbconfig/sizeof"
|
52
56
|
FIXNUM_MAX = (1 << (8 * RbConfig::SIZEOF["long"] - 2)) - 1
|
53
|
-
def distance3 a, b
|
57
|
+
def self.distance3 a, b
|
54
58
|
if a > FIXNUM_MAX && b > FIXNUM_MAX
|
55
59
|
distance3_c a, b
|
56
60
|
else
|
@@ -59,7 +63,7 @@ module DHashVips
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
62
|
-
def distance a, b
|
66
|
+
def self.distance a, b
|
63
67
|
size_a, size_b = [a, b].map do |x|
|
64
68
|
# TODO write a test about possible hash sizes
|
65
69
|
# they were 32 and 128, 124, 120 for MRI 2.0
|
@@ -71,7 +75,7 @@ module DHashVips
|
|
71
75
|
((a ^ b) & (a | b) >> 2 * size_a * size_a).to_s(2).count "1"
|
72
76
|
end
|
73
77
|
|
74
|
-
|
78
|
+
def self.median array
|
75
79
|
h = array.size / 2
|
76
80
|
return array[h] if array[h] != array[h - 1]
|
77
81
|
right = array.dup
|
@@ -81,25 +85,28 @@ module DHashVips
|
|
81
85
|
return right.uniq[1] if left.count(left.last) > right.count(right.first)
|
82
86
|
left.last
|
83
87
|
end
|
84
|
-
|
85
|
-
fail unless
|
86
|
-
fail unless 3 ==
|
87
|
-
fail unless
|
88
|
-
fail unless 2 ==
|
89
|
-
fail unless 2 ==
|
90
|
-
fail unless
|
91
|
-
fail unless
|
92
|
-
fail unless 1 ==
|
88
|
+
private_class_method :median
|
89
|
+
fail unless 2 == median([1, 2, 2, 2, 2, 2, 3])
|
90
|
+
fail unless 3 == median([1, 2, 2, 2, 2, 3, 3])
|
91
|
+
fail unless 3 == median([1, 1, 2, 2, 3, 3, 3])
|
92
|
+
fail unless 2 == median([1, 1, 1, 2, 3, 3, 3])
|
93
|
+
fail unless 2 == median([1, 1, 2, 2, 2, 2, 3])
|
94
|
+
fail unless 2 == median([1, 2, 2, 2, 2, 3])
|
95
|
+
fail unless 3 == median([1, 2, 2, 3, 3, 3])
|
96
|
+
fail unless 1 == median([1, 1, 1])
|
97
|
+
fail unless 1 == median([1, 1])
|
93
98
|
|
94
|
-
def fingerprint
|
99
|
+
def self.fingerprint input, power = 3
|
95
100
|
size = 2 ** power
|
96
|
-
image = Vips::Image
|
97
|
-
|
98
|
-
|
99
|
-
|
101
|
+
image = if input.is_a? Vips::Image
|
102
|
+
input.thumbnail_image(size, height: size, size: :force)
|
103
|
+
else
|
104
|
+
Vips::Image.thumbnail(input, size, height: size, size: :force)
|
105
|
+
end
|
106
|
+
array = (image.has_alpha? ? image.flatten : image).flatten.colourspace("b-w")[0].to_enum.map &:flatten
|
100
107
|
d1, i1, d2, i2 = [array, array.transpose].flat_map do |a|
|
101
|
-
d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i,j| i - j } }
|
102
|
-
m =
|
108
|
+
d = a.zip(a.rotate(1)).flat_map{ |r1, r2| r1.zip(r2).map{ |i, j| i - j } }
|
109
|
+
m = median d.map(&:abs).sort
|
103
110
|
[
|
104
111
|
d.map{ |c| c < 0 ? 1 : 0 }.join.to_i(2),
|
105
112
|
d.map{ |c| c.abs >= m ? 1 : 0 }.join.to_i(2),
|
data/test.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "minitest/autorun"
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "lib/dhash-vips"
|
4
4
|
|
5
5
|
# TODO tests about `fingerprint(4)`
|
6
6
|
|
7
7
|
[
|
8
|
-
[DHashVips::DHash, :hamming, :calculate, 2, 23,
|
8
|
+
[DHashVips::DHash, :hamming, :calculate, 2, 23, 9, 53, 7],
|
9
|
+
|
9
10
|
# vips-8.9.1-Tue Jan 28 13:05:46 UTC 2020
|
10
11
|
# [[0, 14, 26, 27, 31, 27, 32, 28, 43, 43, 34, 37, 37, 34, 35, 42],
|
11
12
|
# [14, 0, 28, 25, 39, 35, 32, 32, 43, 43, 38, 41, 41, 38, 37, 50],
|
@@ -23,7 +24,63 @@ require "dhash-vips"
|
|
23
24
|
# [34, 38, 32, 35, 33, 29, 32, 36, 31, 31, 26, 25, 19, 0, 21, 26],
|
24
25
|
# [35, 37, 27, 26, 40, 34, 23, 27, 28, 28, 29, 30, 26, 21, 0, 23],
|
25
26
|
# [42, 50, 36, 33, 31, 27, 34, 34, 27, 27, 18, 19, 23, 26, 23, 0]]
|
26
|
-
|
27
|
+
|
28
|
+
# vips-8.11.3-Wed Aug 11 09:29:27 UTC 2021
|
29
|
+
# [[0, 17, 25, 30, 30, 26, 35, 30, 42, 42, 35, 32, 36, 32, 34, 42],
|
30
|
+
# [17, 0, 28, 27, 39, 35, 32, 29, 43, 43, 38, 39, 43, 37, 37, 49],
|
31
|
+
# [25, 28, 0, 13, 35, 41, 28, 29, 41, 41, 38, 35, 33, 31, 27, 37],
|
32
|
+
# [30, 27, 13, 0, 36, 36, 31, 34, 38, 38, 35, 32, 40, 34, 26, 32],
|
33
|
+
# [30, 39, 35, 36, 0, 16, 35, 34, 40, 40, 31, 26, 28, 34, 40, 30],
|
34
|
+
# [26, 35, 41, 36, 16, 0, 41, 44, 38, 38, 23, 28, 26, 30, 34, 24],
|
35
|
+
# [35, 32, 28, 31, 35, 41, 0, 11, 27, 27, 38, 35, 33, 33, 21, 35],
|
36
|
+
# [30, 29, 29, 34, 34, 44, 11, 0, 28, 28, 37, 32, 36, 40, 30, 38],
|
37
|
+
# [42, 43, 41, 38, 40, 38, 27, 28, 0, 0, 33, 34, 30, 32, 28, 30],
|
38
|
+
# [42, 43, 41, 38, 40, 38, 27, 28, 0, 0, 33, 34, 30, 32, 28, 30],
|
39
|
+
# [35, 38, 38, 35, 31, 23, 38, 37, 33, 33, 0, 11, 23, 27, 31, 17],
|
40
|
+
# [32, 39, 35, 32, 26, 28, 35, 32, 34, 34, 11, 0, 24, 26, 30, 20],
|
41
|
+
# [36, 43, 33, 40, 28, 26, 33, 36, 30, 30, 23, 24, 0, 20, 26, 22],
|
42
|
+
# [32, 37, 31, 34, 34, 30, 33, 40, 32, 32, 27, 26, 20, 0, 20, 26],
|
43
|
+
# [34, 37, 27, 26, 40, 34, 21, 30, 28, 28, 31, 30, 26, 20, 0, 24],
|
44
|
+
# [42, 49, 37, 32, 30, 24, 35, 38, 30, 30, 17, 20, 22, 26, 24, 0]]
|
45
|
+
|
46
|
+
# v0.1.2.0
|
47
|
+
# [[0, 18, 25, 27, 28, 25, 33, 31, 39, 40, 33, 35, 32, 28, 36, 47],
|
48
|
+
# [18, 0, 31, 25, 34, 33, 33, 33, 39, 38, 37, 43, 40, 36, 40, 53],
|
49
|
+
# [25, 31, 0, 16, 31, 38, 26, 32, 42, 41, 36, 38, 31, 31, 31, 32],
|
50
|
+
# [27, 25, 16, 0, 35, 36, 26, 32, 38, 37, 34, 34, 41, 37, 27, 34],
|
51
|
+
# [28, 34, 31, 35, 0, 17, 39, 37, 41, 44, 31, 27, 26, 32, 32, 33],
|
52
|
+
# [25, 33, 38, 36, 17, 0, 46, 40, 38, 39, 24, 28, 25, 31, 25, 30],
|
53
|
+
# [33, 33, 26, 26, 39, 46, 0, 10, 26, 25, 34, 32, 31, 35, 33, 30],
|
54
|
+
# [31, 33, 32, 32, 37, 40, 10, 0, 26, 27, 34, 32, 33, 33, 33, 34],
|
55
|
+
# [39, 39, 42, 38, 41, 38, 26, 26, 0, 3, 36, 34, 35, 33, 37, 28],
|
56
|
+
# [40, 38, 41, 37, 44, 39, 25, 27, 3, 0, 35, 35, 36, 36, 36, 27],
|
57
|
+
# [33, 37, 36, 34, 31, 24, 34, 34, 36, 35, 0, 10, 23, 31, 23, 22],
|
58
|
+
# [35, 43, 38, 34, 27, 28, 32, 32, 34, 35, 10, 0, 23, 29, 23, 20],
|
59
|
+
# [32, 40, 31, 41, 26, 25, 31, 33, 35, 36, 23, 23, 0, 20, 24, 21],
|
60
|
+
# [28, 36, 31, 37, 32, 31, 35, 33, 33, 36, 31, 29, 20, 0, 20, 25],
|
61
|
+
# [36, 40, 31, 27, 32, 25, 33, 33, 37, 36, 23, 23, 24, 20, 0, 17],
|
62
|
+
# [47, 53, 32, 34, 33, 30, 30, 34, 28, 27, 22, 20, 21, 25, 17, 0]]
|
63
|
+
|
64
|
+
# v0.2.0.0
|
65
|
+
# [[0, 18, 26, 28, 28, 24, 35, 31, 42, 42, 32, 34, 33, 29, 35, 40],
|
66
|
+
# [18, 0, 30, 24, 38, 34, 33, 33, 44, 42, 38, 42, 41, 37, 37, 50],
|
67
|
+
# [26, 30, 0, 16, 34, 38, 29, 35, 42, 40, 36, 38, 31, 31, 31, 36],
|
68
|
+
# [28, 24, 16, 0, 36, 36, 31, 35, 40, 38, 34, 34, 41, 37, 27, 34],
|
69
|
+
# [28, 38, 34, 36, 0, 14, 35, 33, 40, 42, 32, 26, 27, 33, 35, 28],
|
70
|
+
# [24, 34, 38, 36, 14, 0, 43, 39, 38, 40, 24, 28, 25, 31, 29, 28],
|
71
|
+
# [35, 33, 29, 31, 35, 43, 0, 8, 27, 25, 35, 33, 32, 32, 28, 31],
|
72
|
+
# [31, 33, 35, 35, 33, 39, 8, 0, 27, 27, 35, 33, 34, 34, 28, 33],
|
73
|
+
# [42, 44, 42, 40, 40, 38, 27, 27, 0, 2, 34, 32, 31, 33, 31, 28],
|
74
|
+
# [42, 42, 40, 38, 42, 40, 25, 27, 2, 0, 34, 34, 33, 35, 31, 28],
|
75
|
+
# [32, 38, 36, 34, 32, 24, 35, 35, 34, 34, 0, 10, 23, 31, 25, 18],
|
76
|
+
# [34, 42, 38, 34, 26, 28, 33, 33, 32, 34, 10, 0, 23, 29, 25, 16],
|
77
|
+
# [33, 41, 31, 41, 27, 25, 32, 34, 31, 33, 23, 23, 0, 20, 24, 19],
|
78
|
+
# [29, 37, 31, 37, 33, 31, 32, 34, 33, 35, 31, 29, 20, 0, 22, 27],
|
79
|
+
# [35, 37, 31, 27, 35, 29, 28, 28, 31, 31, 25, 25, 24, 22, 0, 23],
|
80
|
+
# [40, 50, 36, 34, 28, 28, 31, 33, 28, 28, 18, 16, 19, 27, 23, 0]]
|
81
|
+
|
82
|
+
[DHashVips::IDHash, :distance, :fingerprint, 8, 21, 23, 72, 0],
|
83
|
+
|
27
84
|
# vips-8.9.1-Tue Jan 28 13:05:46 UTC 2020
|
28
85
|
# [[0, 16, 32, 35, 57, 45, 51, 50, 48, 47, 54, 48, 60, 50, 47, 56],
|
29
86
|
# [16, 0, 30, 34, 58, 47, 55, 56, 47, 50, 57, 49, 62, 52, 52, 61],
|
@@ -41,9 +98,67 @@ require "dhash-vips"
|
|
41
98
|
# [50, 52, 44, 40, 43, 42, 45, 45, 47, 49, 36, 30, 20, 0, 35, 39],
|
42
99
|
# [47, 52, 49, 41, 47, 43, 44, 41, 41, 44, 38, 37, 23, 35, 0, 19],
|
43
100
|
# [56, 61, 49, 51, 48, 42, 47, 42, 46, 43, 25, 27, 28, 39, 19, 0]]
|
101
|
+
|
102
|
+
# vips-8.11.3-Wed Aug 11 09:29:27 UTC 2021
|
103
|
+
# [[0, 17, 30, 35, 55, 46, 51, 54, 48, 46, 57, 48, 59, 52, 49, 54],
|
104
|
+
# [17, 0, 30, 37, 57, 46, 54, 55, 46, 49, 60, 50, 61, 54, 51, 58],
|
105
|
+
# [30, 30, 0, 12, 46, 57, 47, 42, 66, 59, 44, 37, 49, 44, 48, 49],
|
106
|
+
# [35, 37, 12, 0, 54, 67, 44, 41, 58, 53, 48, 41, 56, 42, 46, 48],
|
107
|
+
# [55, 57, 46, 54, 0, 23, 45, 43, 65, 63, 48, 48, 34, 42, 48, 47],
|
108
|
+
# [46, 46, 57, 67, 23, 0, 57, 56, 51, 50, 42, 48, 37, 38, 46, 40],
|
109
|
+
# [51, 54, 47, 44, 45, 57, 0, 6, 33, 34, 49, 43, 49, 41, 45, 47],
|
110
|
+
# [54, 55, 42, 41, 43, 56, 6, 0, 40, 39, 51, 50, 49, 40, 44, 44],
|
111
|
+
# [48, 46, 66, 58, 65, 51, 33, 40, 0, 10, 47, 53, 48, 46, 40, 46],
|
112
|
+
# [46, 49, 59, 53, 63, 50, 34, 39, 10, 0, 50, 57, 50, 49, 40, 43],
|
113
|
+
# [57, 60, 44, 48, 48, 42, 49, 51, 47, 50, 0, 9, 33, 32, 40, 23],
|
114
|
+
# [48, 50, 37, 41, 48, 48, 43, 50, 53, 57, 9, 0, 28, 27, 38, 28],
|
115
|
+
# [59, 61, 49, 56, 34, 37, 49, 49, 48, 50, 33, 28, 0, 21, 24, 27],
|
116
|
+
# [52, 54, 44, 42, 42, 38, 41, 40, 46, 49, 32, 27, 21, 0, 36, 35],
|
117
|
+
# [49, 51, 48, 46, 48, 46, 45, 44, 40, 40, 40, 38, 24, 36, 0, 21],
|
118
|
+
# [54, 58, 49, 48, 47, 40, 47, 44, 46, 43, 23, 28, 27, 35, 21, 0]]
|
119
|
+
|
120
|
+
# v0.1.2.0
|
121
|
+
# [[0, 17, 34, 40, 53, 43, 53, 52, 47, 47, 56, 44, 54, 51, 47, 57],
|
122
|
+
# [17, 0, 35, 33, 56, 45, 56, 52, 48, 49, 58, 49, 64, 57, 53, 58],
|
123
|
+
# [34, 35, 0, 8, 51, 57, 45, 40, 57, 54, 47, 40, 49, 47, 47, 48],
|
124
|
+
# [40, 33, 8, 0, 56, 62, 44, 40, 53, 47, 50, 41, 53, 41, 42, 47],
|
125
|
+
# [53, 56, 51, 56, 0, 21, 41, 48, 72, 65, 46, 47, 36, 43, 43, 43],
|
126
|
+
# [43, 45, 57, 62, 21, 0, 54, 56, 61, 60, 41, 47, 38, 39, 43, 39],
|
127
|
+
# [53, 56, 45, 44, 41, 54, 0, 12, 39, 40, 47, 44, 44, 38, 48, 41],
|
128
|
+
# [52, 52, 40, 40, 48, 56, 12, 0, 35, 36, 51, 50, 47, 39, 41, 43],
|
129
|
+
# [47, 48, 57, 53, 72, 61, 39, 35, 0, 11, 53, 53, 57, 48, 42, 51],
|
130
|
+
# [47, 49, 54, 47, 65, 60, 40, 36, 11, 0, 50, 54, 51, 49, 45, 47],
|
131
|
+
# [56, 58, 47, 50, 46, 41, 47, 51, 53, 50, 0, 13, 32, 36, 38, 23],
|
132
|
+
# [44, 49, 40, 41, 47, 47, 44, 50, 53, 54, 13, 0, 28, 30, 35, 27],
|
133
|
+
# [54, 64, 49, 53, 36, 38, 44, 47, 57, 51, 32, 28, 0, 21, 24, 28],
|
134
|
+
# [51, 57, 47, 41, 43, 39, 38, 39, 48, 49, 36, 30, 21, 0, 31, 35],
|
135
|
+
# [47, 53, 47, 42, 43, 43, 48, 41, 42, 45, 38, 35, 24, 31, 0, 19],
|
136
|
+
# [57, 58, 48, 47, 43, 39, 41, 43, 51, 47, 23, 27, 28, 35, 19, 0]]
|
137
|
+
|
138
|
+
# v0.2.0.0
|
139
|
+
# [[0, 17, 34, 40, 53, 43, 53, 52, 47, 47, 56, 44, 54, 51, 47, 57],
|
140
|
+
# [17, 0, 35, 33, 56, 45, 56, 52, 48, 49, 58, 49, 64, 57, 53, 58],
|
141
|
+
# [34, 35, 0, 8, 51, 57, 45, 40, 57, 54, 47, 40, 49, 47, 47, 48],
|
142
|
+
# [40, 33, 8, 0, 56, 62, 44, 40, 53, 47, 50, 41, 53, 41, 42, 47],
|
143
|
+
# [53, 56, 51, 56, 0, 21, 41, 48, 72, 65, 46, 47, 36, 43, 43, 43],
|
144
|
+
# [43, 45, 57, 62, 21, 0, 54, 56, 61, 60, 41, 47, 38, 39, 43, 39],
|
145
|
+
# [53, 56, 45, 44, 41, 54, 0, 12, 39, 40, 47, 44, 44, 38, 48, 41],
|
146
|
+
# [52, 52, 40, 40, 48, 56, 12, 0, 35, 36, 51, 50, 47, 39, 41, 43],
|
147
|
+
# [47, 48, 57, 53, 72, 61, 39, 35, 0, 11, 53, 53, 57, 48, 42, 51],
|
148
|
+
# [47, 49, 54, 47, 65, 60, 40, 36, 11, 0, 50, 54, 51, 49, 45, 47],
|
149
|
+
# [56, 58, 47, 50, 46, 41, 47, 51, 53, 50, 0, 13, 32, 36, 38, 23],
|
150
|
+
# [44, 49, 40, 41, 47, 47, 44, 50, 53, 54, 13, 0, 28, 30, 35, 27],
|
151
|
+
# [54, 64, 49, 53, 36, 38, 44, 47, 57, 51, 32, 28, 0, 21, 24, 28],
|
152
|
+
# [51, 57, 47, 41, 43, 39, 38, 39, 48, 49, 36, 30, 21, 0, 31, 35],
|
153
|
+
# [47, 53, 47, 42, 43, 43, 48, 41, 42, 45, 38, 35, 24, 31, 0, 19],
|
154
|
+
# [57, 58, 48, 47, 43, 39, 41, 43, 51, 47, 23, 27, 28, 35, 19, 0]]
|
155
|
+
|
44
156
|
].each do |lib, dm, calc, min_similar, max_similar, min_not_similar, max_not_similar, bw_exceptional|
|
45
157
|
|
46
158
|
describe lib do
|
159
|
+
require "fileutils"
|
160
|
+
require "digest"
|
161
|
+
require "mll"
|
47
162
|
|
48
163
|
# these are false positive by idhash
|
49
164
|
# 6d97739b4a08f965dc9239dd24382e96.jpg
|
@@ -62,25 +177,21 @@ require "dhash-vips"
|
|
62
177
|
[ %w{
|
63
178
|
71662d4d4029a3b41d47d5baf681ab9a.jpg ad8a37f872956666c3077a3e9e737984.jpg
|
64
179
|
}, bw_exceptional, bw_exceptional], # these are the same photo but of different size and colorspace
|
65
|
-
].each do |
|
66
|
-
|
67
|
-
require "fileutils"
|
68
|
-
require "digest"
|
69
|
-
require "mll"
|
180
|
+
].each do |_images, min, max|
|
70
181
|
|
71
182
|
require_relative "common"
|
72
|
-
images =
|
183
|
+
images = _images.map{ |_| download_if_needed "test_images/#{_}" }
|
73
184
|
|
74
185
|
hashes = images.map &lib.method(calc)
|
75
186
|
table = MLL::table[lib.method(dm), [hashes], [hashes]]
|
76
187
|
|
77
|
-
|
78
|
-
|
79
|
-
PP.pp table, STDERR
|
80
|
-
STDERR.puts ""
|
188
|
+
# STDERR.puts ""
|
189
|
+
# require "pp"
|
190
|
+
# PP.pp table, STDERR
|
191
|
+
# STDERR.puts ""
|
81
192
|
|
82
193
|
hashes.size.times.to_a.repeated_combination(2) do |i, j|
|
83
|
-
it do
|
194
|
+
it "#{_images[i]} #{_images[j]}" do
|
84
195
|
case
|
85
196
|
when i == j
|
86
197
|
assert_predicate table[i][j], :zero?
|
@@ -96,6 +207,19 @@ require "dhash-vips"
|
|
96
207
|
|
97
208
|
end
|
98
209
|
|
210
|
+
it "accepts Vips::Image" do
|
211
|
+
# https://github.com/libvips/ruby-vips/issues/349
|
212
|
+
lib.public_send calc, Vips::Image.new_from_buffer("GIF89a\x01\x00\x01\x00\x80\x01\x00\xFF\xFF\xFF\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;", "")
|
213
|
+
end
|
214
|
+
|
99
215
|
end
|
100
216
|
|
101
217
|
end
|
218
|
+
|
219
|
+
describe DHashVips::IDHash do
|
220
|
+
it "does not call distance3_ruby" do
|
221
|
+
DHashVips::IDHash.stub :distance3_ruby, ->*{fail} do
|
222
|
+
assert_equal 0, DHashVips::IDHash.distance3((2<<256)-1, (2<<256)-1)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhash-vips
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-vips
|
@@ -71,8 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
|
-
|
75
|
-
rubygems_version: 2.6.14.4
|
74
|
+
rubygems_version: 3.3.25
|
76
75
|
signing_key:
|
77
76
|
specification_version: 4
|
78
77
|
summary: dHash and IDHash perceptual image hashing/fingerprinting
|