项目作者: teachbase

项目描述 :
Image comparison library
高级语言: Ruby
项目地址: git://github.com/teachbase/imatcher.git
创建时间: 2016-02-15T15:12:21Z
项目社区:https://github.com/teachbase/imatcher

开源协议:MIT License

下载


Gem Version Build Status

Imatcher

Compare PNG images in pure Ruby (uses ChunkyPNG) using different algorithms.
This is an utility library for image regression testing.

Installation

Add this line to your application’s Gemfile:

  1. gem 'imatcher'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install imatcher

Additionally, you may want to install oily_png to improve performance when using MRI. Just install it globally or add to your Gemfile.

Modes

Imatcher supports different ways (modes) of comparing images.

Source images used in examples:


Base (RGB) mode

Compare pixels by values, resulting score is a ratio of unequal pixels.
Resulting diff represents per-channel difference.

Grayscale mode

Compare pixels as grayscale (by brightness and alpha), resulting score is a ratio of unequal pixels (with respect to provided tolerance).

Resulting diff contains grayscale version of the first image with different pixels highlighted in red and red bounding box.

Delta

Compare pixels using Delta E distance.
Resulting diff contains grayscale version of the first image with different pixels highlighted in red (with respect to diff score).

Usage

  1. # create new matcher with default threshold equals to 0
  2. # and base (RGB) mode
  3. cmp = Imatcher::Matcher.new
  4. cmp.mode #=> Imatcher::Modes::RGB
  5. # create matcher with specific threshold
  6. cmp = Imatcher::Matcher.new threshold: 0.05
  7. cmp.threshold #=> 0.05
  8. # create zero-tolerance grayscale matcher
  9. cmp = Imatcher::Matcher.new mode: :grayscale, tolerance: 0
  10. cmp.mode #=> Imatcher::Modes::Grayscale
  11. res = cmp.compare(path_1, path_2)
  12. res #=> Imatcher::Result
  13. res.match? #=> true
  14. res.score #=> 0.0
  15. # Return diff image object
  16. res.difference_image #=> Imatcher::Image
  17. res.difference_image.save(new_path)
  18. # without explicit matcher
  19. res = Imatcher.compare(path_1, path_2, options)
  20. # equals to
  21. res = Imatcher::Matcher.new(options).compare(path_1, path_2)

Excluding rectangle


You can exclude rectangle from comparing by passing :exclude_rect to compare.
E.g., if path_1 and path_2 contain images above

  1. Imatcher.compare(path_1, path_2, exclude_rect: [200, 150, 275, 200]).match? # => true

[200, 150, 275, 200] is array of two vertices of rectangle — (200, 150) is left-top vertex and (275, 200) is right-bottom.

Including rectangle

You can set bounds of comparing by passing :include_rect to compare with array similar to previous example

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/teachbase/imatcher.

License

The gem is available as open source under the terms of the MIT License.