imgPixelmatch function

Future<(double, Uint8List)> imgPixelmatch(
  1. dynamic img1,
  2. dynamic img2,
  3. Map<String, dynamic> options
)

Compares two Image objects and calculates the number of differing pixels.

Parameters:

  • img1: The first Image object to compare.
  • img2: The second Image object to compare.
  • options: A map of options to customize the comparison.

Returns a Future that completes with a tuple containing:

  • A double representing the ratio of differing pixels to the total number of pixels in the images.
  • A Uint8List containing the raw RGBA byte data of the difference image.

Implementation

Future<(double, Uint8List)> imgPixelmatch(Image img1, Image img2, Map<String, dynamic> options) async {
  final rgba1 = await imgToRgba(img1);
  final rgba2 = await imgToRgba(img2);
  final diff = Uint8List(rgba1.length);
  final numPix = pixelmatch(rgba1, rgba2, diff, img1.width, img1.height, options);
  final ratio = numPix / (img1.width * img1.height);
  return (ratio, diff);
}