Sha256: f8de68d1cc4db540e4cc9f13b221403aaad632315fa2b5f8476920f88332c5a5

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

# encoding: UTF-8
require 'RMagick'
require_relative '../diff'

module Simulacrum
  # The RMagicDiff class implements image diffing using ImageMagick
  class RMagicDiff < Simulacrum::Diff
    def delta
      @delta * 100
    end

    private

    def compare
      a = Magick::Image.read(@a_path)
      b = Magick::Image.read(@b_path)
      @image, @delta = square_root_mean_squared(a, b)
    end

    def square_root_mean_squared(a, b)
      # Calculate the Square Root Mean Squared Error for the comparison of the
      # two images.
      #
      # Gets the color difference for each pixel, and square it, average all
      # the squared differences, then return the square root.
      #
      # http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17284
      a[0].compare_channel(b[0], Magick::MeanSquaredErrorMetric)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simulacrum-0.3.2 lib/simulacrum/diff/rmagick.rb
simulacrum-0.3.1 lib/simulacrum/diff/rmagick.rb
simulacrum-0.3.0 lib/simulacrum/diff/rmagick.rb