ssimsort 0.1.3 → 0.1.5

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
  SHA1:
3
- metadata.gz: 0d2cb4217d6141e0a77c7bba104575151eea0844
4
- data.tar.gz: 6d5c5137dbc3c9abfe3d432076f40758db163238
3
+ metadata.gz: adfe74cb2e85227dd8cf598400e1275c170e4320
4
+ data.tar.gz: 6abc4d25a01a20db39e36e152b94251f129f02d1
5
5
  SHA512:
6
- metadata.gz: 378fa86ba675c020e3ceb786519cf35a01cedd6b6ca908f5642456cf4060c97e751de58c66cd068f2a30ee4ca912abfdc048718dc18b088ee3cb03ba3682524a
7
- data.tar.gz: 12113ffe5100d222ca47565afa2642104745b912393ae187727cdd94a6c1705d7a10aaacf848e933e2caa6654d98efd7ac9b3306675d749913f51310bcc01f52
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.sort(ARGV[0],ARGV[1],*ARGV[2].to_i)
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=300)
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(3)
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 < tolerance
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ssimsort'
3
- s.version = '0.1.3'
3
+ s.version = '0.1.5'
4
4
  s.date = '2013-11-25'
5
5
  s.summary = "SsimSort"
6
6
  s.description = "Sort images easily by their similarity"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssimsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Galaad Gauthier