rpdiff 1.0.0
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 +7 -0
- data/README +5 -0
- data/bin/rpdiff +31 -0
- data/lib/rpdiff.rb +43 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af35e2511342dba9d3c08c126b947a999e448d2e
|
4
|
+
data.tar.gz: 9077537a63e74d9f736a1586dcefbe21a1271c1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f810d02144f1063f6647b4fe2a229f53db5fab4e46605db3f1a2819c7c9b209f4b5ac9dc491588f19cc8513413231844c35f9ef34ed3f9771f4a4c15122364b
|
7
|
+
data.tar.gz: 72c4699264956ee3f1e3171b95d0b5a08d2d06e005ab57f1ce7378bcb0ca78d03d80e06f4506801ddeef8ccab22236c53b6a3839fc91143acbeac5f8153534f3
|
data/README
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
This is a wrapper on Perceptual diff (http://pdiff.sourceforge.net/).
|
2
|
+
|
3
|
+
The basic application is to compare images and see the differences or evaluate pixel by pixel how different they are. This is practical for a deployment/QA environment as well as other image processing applications, like finding similarities.
|
4
|
+
|
5
|
+
Based on https://github.com/aaronfeng/perceptual_diff/blob/master/perceptual_diff.rb
|
data/bin/rpdiff
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative "../lib/rpdiff.rb"
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Compares image1.tif and image2.tif using a perceptually based image metric. Options:"
|
9
|
+
|
10
|
+
opts.on("-verbose", "Turns on verbose mode") {|val| options[:verbose] = val}
|
11
|
+
opts.on("-debug", "Turns on perceptualdiff command line output") {|val| options[:debug] = val}
|
12
|
+
opts.on("-output out.ppm", String, "Write difference to the file o.ppm") {|val| options[:output] = val}
|
13
|
+
opts.on("-fov deg", String, "Field of view in degrees (0.1 to 89.9)") {|val| options[:fov] = val}
|
14
|
+
opts.on("-threshold p", Integer, "#pixels p below which differences are ignored") {|val| options[:threshold] = val}
|
15
|
+
opts.on("-gamma g", Float, "Value to convert rgb into linear space (default 2.2)") {|val| options[:gamma] = val}
|
16
|
+
opts.on("-luminance l", Float, "White luminance (default 100.0 cdm^-2)") {|val| options[:luminance] = val}
|
17
|
+
opts.on("-luminanceonly", "Only consider luminance; ignore chroma (color) in the comparison") {|val| options[:luminanceonly] = val}
|
18
|
+
opts.on("-match_percentage", "Process pixel match in %") {|val| options[:match_percentage] = val}
|
19
|
+
|
20
|
+
opts.parse!
|
21
|
+
if ARGV.count == 2
|
22
|
+
img1, img2 = ARGV
|
23
|
+
|
24
|
+
match_percentage = options.delete :match_percentage
|
25
|
+
rpdiff = RPDiff.new(img1, img2, options)
|
26
|
+
rpdiff.diff
|
27
|
+
else
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
data/lib/rpdiff.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class RPDiff
|
2
|
+
|
3
|
+
attr_reader :visibly_different, :identical, :indistinguishable, :pixel_difference,
|
4
|
+
:img1, :img2, :fov, :threshold, :gamma, :luminance
|
5
|
+
|
6
|
+
def initialize(img1, img2, options={})
|
7
|
+
@img1, @img2, @options = img1, img2, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def diff
|
11
|
+
@indistinguishable = @visibly_different = @identical = false
|
12
|
+
@pixel_difference = 0
|
13
|
+
|
14
|
+
opts = "#{@img1} #{@img2} "
|
15
|
+
@options.each {|k, v| opts << "-#{k} #{v}" if v }
|
16
|
+
io = `perceptualdiff -verbose #{opts}`
|
17
|
+
|
18
|
+
io.split(/\n/).each do |line|
|
19
|
+
@fov = $1 if line =~ /Field of view is (\d+\.\d+) degrees/
|
20
|
+
@threshold = $1 if line =~ /Threshold pixels is (\d+) pixels/
|
21
|
+
@gamma = $1 if line =~ /The Gamma is (\d+\.\d+)/
|
22
|
+
@luminance = $1 if line =~ /The Display's luminance is (\d+\.\d+) candela per meter squared/
|
23
|
+
@pixel_difference = $1 if line =~ /(\d+) pixels are different/
|
24
|
+
@visibly_different = true if line =~ /FAIL: Images are visibly different/
|
25
|
+
@identical = true if line =~ /PASS: Images are binary identical/
|
26
|
+
@indistinguishable = true if line =~ /PASS: Images are perceptually indistinguishable/
|
27
|
+
end
|
28
|
+
|
29
|
+
if @options[:match_percentage]
|
30
|
+
calculate_match_percentage
|
31
|
+
end
|
32
|
+
|
33
|
+
puts io
|
34
|
+
end
|
35
|
+
|
36
|
+
#Optional gem requirement to get a % value out of image similarity.
|
37
|
+
def calculate_match_percentage
|
38
|
+
require 'fastimage'
|
39
|
+
@image_sizes = FastImage.size(@img1)
|
40
|
+
@match_percentage = 100 - (@pixel_difference.to_f * 100 / (@image_sizes.first * @image_sizes.last).to_f)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpdiff
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Benmergui
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A thin wrapper on Perceptual Diff for ease of use.
|
14
|
+
email: gabriel.benmergui@gmail.com
|
15
|
+
executables:
|
16
|
+
- rpdiff
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README
|
21
|
+
- bin/rpdiff
|
22
|
+
- lib/rpdiff.rb
|
23
|
+
homepage: http://github.com/conanbatt/rpdiff
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- - lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Rpdiff is a ruby wrapper on Perceptual diff
|
46
|
+
test_files: []
|