diff_image2 1.0.3 copy "diff_image2: ^1.0.3" to clipboard
diff_image2: ^1.0.3 copied to clipboard

A package to get the difference between two images. Currently supports fetching images from web and from local memory.

diff_image #

A Dart Package to get the % difference between two images of the same width and height.

diff_image2 is a Dart version of this with changes on visualization and , you guessed it, the language.

Example #

A simple usage example:

import 'package:diff_image2/diff_image.dart';
import 'package:image/image.dart';

final FIRST_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-cs.png';
final SECOND_IMAGE = 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-node.png';

void foo() async {
  try {
      var diff = await DiffImage.compareFromUrl(
        FIRST_IMAGE,
        SECOND_IMAGE,
      );
      print('The difference between images is: ${diff.value} %');
  } catch(e) {
      print(e);
  }
}

void goo(Image first, Image second) {
  try {
    var diff = DiffImage.compareFromMemory(
      first,
      second,
    );
    print('The difference between images is: ${diff.diffValue} %');
  } catch(e) {
    print(e);
  }
}

main() {
  foo();
  /*These can be obtained with any method*/
  Image first;
  Image second;
  // Here is posible to manipulate both images before passing them
  // to the function.
  goo(first, second);
}

A more detailed example can be found here

Features #

  1. Currently there is support for comparing images fetched from urls and from memory or storage.
  2. The compareFromUrl definition is:
  static Future<DiffImgResult> compareFromUrl(
    dynamic firstImgSrc,
    dynamic secondImgSrc, {
    bool asPercentage = true,
    bool ignoreAlpha = true,
  }) async{...}
  1. And the compareFromMemory definition is:
  static DiffImgResult compareFromMemory(
    Image firstImg,
    Image secondImg, {
    bool asPercentage = true,
    bool ignoreAlpha = true,
  }) {...}

where:

  • ignoreAlpha allows to decide whether to take alpha from RGBA into account for the calculation
  • asPercentage set the format of the output (as percentage or between 0-1)

Both methods return an DiffImgResult, a model which contains two elements: An image showing the differences between both images and the numeric value representing the difference (as percentage or not).

  1. A function called saveDiffImg which saves a png showing the differences between firstImg and secondImg (currently not available on Dart Web).

Sample Results #

First Image #

flutter_logo

Second Image #

android_logo

Difference Percentage #

With Alpha : 35.67169421487167 %

Without Alpha : 34.83905183744361 %

Difference Image #

DiffImg

Suggestions and bugs #

Please file feature requests, suggestions and bugs at the issue tracker.

4
likes
0
points
216
downloads

Publisher

unverified uploader

Weekly Downloads

A package to get the difference between two images. Currently supports fetching images from web and from local memory.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

http, image

More

Packages that depend on diff_image2