ssimsort 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ssimsort +5 -2
- data/lib/ssimsort.rb +22 -5
- data/ssimsort.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adfe74cb2e85227dd8cf598400e1275c170e4320
|
4
|
+
data.tar.gz: 6abc4d25a01a20db39e36e152b94251f129f02d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6223df1608c4c1a017ce8c3d68e9a43a682096fc8bc9a71594efe6b3fe27e430f49a2aecc46fac4565cd90bced1bb8d807d6668e56c93f665671ebf859b43d2a
|
7
|
+
data.tar.gz: 3ff54b3258a449255ebee47846a39f947e2ee66f8c3f850513ffb9656a09d1e22f64f823fb80717f7cb5ba5114e4b6ee777910e9d8006e1e5c6079f2999c12c0
|
data/bin/ssimsort
CHANGED
@@ -3,5 +3,8 @@
|
|
3
3
|
root = File.expand_path("../..", __FILE__)
|
4
4
|
require "#{root}/lib/ssimsort.rb"
|
5
5
|
|
6
|
-
|
7
|
-
SsimSort.
|
6
|
+
case ARGV[0]
|
7
|
+
when "-sc" then SsimSort.sort_comp(ARGV[1],ARGV[2],ARGV[3])
|
8
|
+
when "-s" then SsimSort.sort(ARGV[1],ARGV[2],*ARGV[3])
|
9
|
+
else puts "SSIMSORT:\n-s <input_dir>,<output_dir>,[<tolerance>]\n-sc <base_file>,<input_dir>,<output_dir>\n"
|
10
|
+
end
|
data/lib/ssimsort.rb
CHANGED
@@ -14,7 +14,7 @@ module SsimSort
|
|
14
14
|
end
|
15
15
|
|
16
16
|
|
17
|
-
def SsimSort.get_lum(img,px=
|
17
|
+
def SsimSort.get_lum(img,px=100)
|
18
18
|
img = img.scale(px,px)
|
19
19
|
lum_average = img.get_pixels(0, 0, img.columns, img.rows).map do |p|
|
20
20
|
p.to_HSL[2]
|
@@ -30,7 +30,7 @@ module SsimSort
|
|
30
30
|
moy_x, moy_y = x.mean, y.mean
|
31
31
|
a = (2*moy_x*moy_y+cA)*(2*(cov(x,y))+cB)
|
32
32
|
b = (moy_x**2+moy_y**2+cA)*(var_x+var_y+cB)
|
33
|
-
(a/b) < 0 ? 0 : (a/b).round(
|
33
|
+
(a/b) < 0 ? 0 : (a/b).round(4)
|
34
34
|
end
|
35
35
|
|
36
36
|
|
@@ -43,14 +43,31 @@ module SsimSort
|
|
43
43
|
set.each do |file1,file2|
|
44
44
|
path = "#{output_path}/#{file1.split("/").last}/"
|
45
45
|
simil = SsimSort.ssim(file1,file2)
|
46
|
-
if simil
|
47
|
-
next
|
48
|
-
elsif simil > tolerance
|
46
|
+
if simil > tolerance
|
49
47
|
FileUtils.makedirs(path) unless File.exists?(path)
|
50
48
|
FileUtils.cp(file2,path)
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
53
|
+
def SsimSort.sort_comp(filecomp_path,input_path,output_path)
|
54
|
+
formats = /(.jpg$|.png$|.JPG$|.jpeg$|.PNG$|.gif$|.bmp$|.BMP$)/
|
55
|
+
filecomp = File.absolute_path(filecomp_path)
|
56
|
+
output_path = File.absolute_path(output_path+"/")
|
57
|
+
files = Dir.entries(input_path).map {|file| File.absolute_path("#{input_path}/#{file}")}
|
58
|
+
files.shift(2) #Remove . and ..
|
59
|
+
files.select!{|f| formats=~ f}
|
60
|
+
sim_dict = {}
|
61
|
+
FileUtils.mkdir(output_path) unless File.exists?(output_path)
|
62
|
+
files.each do |file|
|
63
|
+
simil = SsimSort.ssim(filecomp,file)
|
64
|
+
sim_dict[file] = simil
|
65
|
+
end
|
66
|
+
sim_dict = sim_dict.sort_by {|k,v| v}.reverse.map {|k,v| k}
|
67
|
+
sim_dict.each_with_index do |k,i|
|
68
|
+
FileUtils.cp(k,"#{output_path}/#{i}#{File.extname(k)}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
55
72
|
end
|
56
73
|
|
data/ssimsort.gemspec
CHANGED