PixeldriftFind perceptible pixel differences.
This module finds the number of perceptually differing pixels between two equally sized sRGB images with an alpha component. It is mostly suitable for comparing synthetic images: diagrams, user interface screenshots, rendering algorithms outputs, etc.
To take into account the alpha component images are first blended against an opaque white background before testing their pixels for difference using a perceptual color metric.
Anti-aliased pixels can be detected and optionally ignored by the comparison.
References. The algorithm is based on the pixelmatch JavaScript library. In contrast to the latter it performs alpha blending computations in linear space and uses a simplified anti-aliasing pixel detection algorithm which, for now, acts more like an edge detection filter. The color metric is described in this paper:
module Bigbytes : sig ... endBigarrays of bytes.
type srgb_pixels = Bigbytes.tThe type for pixel data in sRGB space with an alpha component.
Pixels are stored in a linear buffer, line-by-line, from left to right and top to bottom in RGBA order with one byte per component.
The type for specifying an image containing a color coded difference map. See diff_map for details.
val diff_map :
?luma_alpha:float ->
?diff:uint32 ->
?diff_darken:uint32 ->
?aa:uint32 ->
srgb_pixels ->
diff_mapdiff_map ~luma_alpha ~diff ~diff_darken ~aa_color pixels specifies a pixel difference image in pixels as follows:
luma_alpha (defaults to 0.1). If luma_alpha is 0. then no blending occurs and the difference map background is a black transparent color.diff (defaults to 0xD7_19_1C_FFl)diff_darken (defaults equal to diff).aa (defaults to 0xFF_FF_99_FFl).val mask_diff_map :
?diff:uint32 ->
?diff_darken:uint32 ->
srgb_pixels ->
diff_mapmask_diff_map is diff_map ~luma_alpha:0 ~aa:0l. With these parameters only differing pixels are rendered over a black transparent background.
val diff_map_pixels : diff_map -> srgb_pixelsdiff_map_pixels m are the pixels of m.
val count :
?tol:float ->
ignore_aa:bool ->
w:int ->
h:int ->
ref:srgb_pixels ->
test:srgb_pixels ->
diff_map:diff_map option ->
unit ->
intcount ~tol ~ignore_aa ~color_space ~w ~h ~ref ~test ~diff_map () is the number of pixels differing when comparing the w⨯h pixels of ref to test with:
ignore_aa determines whether anti-aliasing pixels should be detected and ignored for the sake of comparison.color_space is the color space in which all pixels are assumed to live in (including the diff_map if specified).diff_map if specified, writes an image of the differences as specified by the diff_map value.tol is a matching tolerance the smaller the more sensitive the comparison is. Ranges from 0. to 1., defaults to 0.1.Raises Invalid_argument if ref, test and diff_map do not have exactly w⨯h pixels.