I’ve published image version 0.34.0. Special shoutout to @sodapopcan who demonstrated amazing patience while I fuddled though making text images work consistently and correctly.
Example of Image.compare/3
The main feature of this release is a way to compare images and return a similarity score and a difference image. This is similar to the same function in ImageMagick.
iex> image_1 = Image.open!("./test/support/images/Kamchatka-2019-8754.jpg")
# Image 2 is the same image, only with a cat overlayed upon it.
iex> cat = Image.open! "./test/support/images/cat.png"
iex> image_2 = Image.compose!(i, cat, x: :middle, y: :center) |> Image.flatten!
# Now we can compare the image with the defaults of
# `metric: :ae, difference_color: :red, saturation: 1.0, brightness: 1.0, difference_boost: 1.5`
iex> {:ok, metric, difference_image} = Image.compare(image_1, image_2)
{:ok, 0.13152029520295203,
%Vix.Vips.Image{ref: #Reference<0.1501890617.2351562776.180408>}}
# Note how the pixels that were different between the two images are masked in red overlaid on the original image. Its possible to adjust the brightness and saturation of the base image and to boost them for the difference pixels. Here's an example:
iex> {:ok, metric, difference_image} = Image.compare image_1, image_2, brightness: 0.5, saturation: 0.2, difference_boost: 2.0
{:ok, 0.13152029520295203,
%Vix.Vips.Image{ref: #Reference<0.1501890617.2351562776.180435>}}
Note how the difference pixels stand out more strongly. You can also see there is a color gradient to the difference pixels. The shading indicates how much different (mathematical difference, not perceptual difference) the pixels are.