-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
/.byebug_history | ||
.DS_Store | ||
*.jpg | ||
*.png | ||
/test_images/*.png | ||
|
||
/temp.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env ruby | ||
Signal.trap(:INT){ abort "\n(interrupted by SIGINT)" } | ||
|
||
unless 2 == ARGV.size | ||
puts "this command is to compare two images" | ||
puts "usage: #{__FILE__} <path to image1> <path to image2>" | ||
exit | ||
end | ||
|
||
require_relative "../lib/dhash-vips" | ||
ha, hb = ARGV.map{ |filename| DHashVips::IDHash.fingerprint filename } | ||
puts "distance: #{d1 = DHashVips::IDHash.distance ha, hb}" | ||
size = 2 ** 3 | ||
shift = 2 * size * size | ||
ai = ha >> shift | ||
ad = ha - (ai << shift) | ||
bi = hb >> shift | ||
bd = hb - (bi << shift) | ||
|
||
_127 = shift - 1 | ||
_63 = size * size - 1 | ||
# width = 800 | ||
# height = 800 | ||
|
||
d2 = 0 | ||
a, b = [[ad, ai, ARGV[0]], [bd, bi, ARGV[1]]].map do |xd, xi, path| | ||
puts File.basename path | ||
hor = Array.new(size){Array.new(size){" "}} | ||
ver = Array.new(size){Array.new(size){" "}} | ||
_127.downto(0).each_with_index do |i, ii| | ||
if i > _63 | ||
y, x = (_127 - i).divmod size | ||
else | ||
x, y = (_63 - i).divmod size | ||
end | ||
if xi[i] > 0 | ||
target, c = if i > _63 | ||
[ver, %w{ v ^ }[xd[i]]] | ||
else | ||
[hor, %w{ > < }[xd[i]]] | ||
end | ||
target[y][x] = c | ||
end | ||
if ai[i] + bi[i] > 0 && ad[i] != bd[i] | ||
d2 += 1 | ||
target = if i > _63 | ||
ver | ||
else | ||
hor | ||
end | ||
target[y][x] = "\e[7m#{target[y][x]}\e[27m" | ||
end | ||
end | ||
hor.zip(ver).each{ |_| puts _.join " " } | ||
end | ||
abort "something went wrong" unless d1 * 2 == d2 | ||
puts "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = "dhash-vips" | ||
spec.version = "0.2.3.0" | ||
spec.version = "0.2.4.0" | ||
spec.summary = "dHash and IDHash perceptual image hashing/fingerprinting" | ||
spec.metadata = {"source_code_uri" => "https://github.com/nakilon/dhash-vips"} | ||
|
||
spec.author = "Victor Maslov aka Nakilon" | ||
spec.email = "[email protected]" | ||
spec.license = "MIT" | ||
spec.metadata = {"source_code_uri" => "https://github.com/nakilon/dhash-vips"} | ||
|
||
spec.add_dependency "ruby-vips", "~> 2.0", "!= 2.1.0", "!= 2.1.1" | ||
|
||
spec.require_path = "lib" | ||
spec.extensions = %w{ extconf.rb } | ||
spec.files = %w{ LICENSE.txt dhash-vips.gemspec lib/dhash-vips.rb idhash.c lib/dhash-vips-post-install-test.rb } + spec.extensions | ||
spec.files = %w{ LICENSE.txt dhash-vips.gemspec lib/dhash-vips.rb idhash.c lib/dhash-vips-post-install-test.rb } + spec.extensions + | ||
%w{ bin/idhash } | ||
spec.executables = %w{ idhash } | ||
spec.bindir = "bin" | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.