class RPDiff
Attributes
fov[R]
gamma[R]
identical[R]
img1[R]
img2[R]
incomparable[R]
indistinguishable[R]
luminance[R]
match_percentage[R]
pixel_difference[R]
threshold[R]
visibly_different[R]
Public Class Methods
new(img1, img2, options={})
click to toggle source
# File lib/rpdiff.rb, line 9 def initialize(img1, img2, options={}) @img1, @img2, @options = img1, img2, options end
Public Instance Methods
calculate_match_percentage()
click to toggle source
Optional gem requirement to get a % value out of image similarity.
# File lib/rpdiff.rb, line 36 def calculate_match_percentage return 0 if incomparable @image_sizes = FastImage.size(@img1) @match_percentage = 100 - (@pixel_difference.to_f * 100 / (@image_sizes.first * @image_sizes.last).to_f) end
diff()
click to toggle source
# File lib/rpdiff.rb, line 13 def diff @indistinguishable = @visibly_different = @identical = false @pixel_difference = 0 opts = "#{@img1} #{@img2} " @options.each {|k, v| opts << "-#{k} #{v} "} io = `perceptualdiff #{opts}` io.split(/\n/).each do |line| @fov = $1 if line =~ /Field of view is (\d+\.\d+) degrees/ @threshold = $1 if line =~ /Threshold pixels is (\d+) pixels/ @gamma = $1 if line =~ /The Gamma is (\d+\.\d+)/ @luminance = $1 if line =~ /The Display's luminance is (\d+\.\d+) candela per meter squared/ @pixel_difference = $1 if line =~ /(\d+) pixels are different/ @visibly_different = true if line =~ /FAIL: Images are visibly different/ @identical = true if line =~ /PASS: Images are binary identical/ @indistinguishable = true if line =~ /PASS: Images are perceptually indistinguishable/ @incomparable = true if line =~ /FAIL: Image dimensions do not match/ end io end