For when you want to see if two images aren't quite the same.
Flexo.compare(
image_a_path : String,
image_b_path : String,
threshold : Float32 = 0.0) : Result
Compares two images of the same size at the given file paths with an optional threshold for if they are considered a match. Returns a Result
Result#score
The ratio of pixels that are different between the two images and the total number of pixels of one of those images.
Result#match?
A boolean value that represents whether the two compared images are a match given the threshold provided when comparing them.
Result#save(path : String)
Saves the diff image between the two images to the given path. Differences appear as the colour StumpyCore::RGBA::LIME
overlaid on the first image.
-
shards init
-
Add the dependency to
shards.yml
... dependencies: flexo: github: pschulze/flexo version: "~> 0.1" ...
-
shards install
require "flexo"
result = Flexo.compare("path/to/first/image.png", "path/to/second/image.png")
puts result.score
puts result.match?
result.save("output/path/of/diff/image.png")
-
Run:
git clone git@github.com:pschulze/flexo.git cd flexo shards install crystal examples/corgi_comparison.cr