I am a flutter developer. My need is to compare two images and highlight the difference (between two images) in a new image in flutter?
Two images First image and Second image.
My requirement is to compare those images and highlight the difference region in another image Difference image. I am trying to achieve screenshot based UI testing in flutter and need to fail the test cases if there is any differences between two images.
Please find the below screenshots for reference.
Is there any package in flutter/dart to achieve the same output?
Thanks and regards,
Ashwin
The similarity of the two images is detected using the package “imagehash”. If two images are identical or almost identical, the imagehash difference will be 0. Two images are more similar if the imagehash difference is closer to 0.
In Flutter, displaying an image can be done by using Image widget. Flutter provides a named constructor File. Image which can be used if the image source is from a file. Alternatively, you can also use FileImage .
The Flutter supports many image formats, such as JPEG, WebP, PNG, GIF, animated WebP/GIF, BMP, and WBMP. Displaying images is the fundamental concept of most of the mobile apps. Flutter has an Image widget that allows displaying different types of images in the mobile application.
A few months ago I read your question, and today I've just uploaded a package that do what you want.
import 'package:diff_image/diff_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';
num getDiff() async{
try{
var diff = await DiffImage.compareFromUrl(
FIRST_IMAGE,
SECOND_IMAGE,
saveDiff:True
);
print('The difference between images is: $diff %');
return diff;
} catch(e){
print(e);
}
}
main() {
getDiff();
}
With two images as input, it returns the difference ratio between them, and exactly as you want, save the "diff image" as png.
I guess it can solve your problem but if you need something more specific, feel free to ask me the feature you need.
My team and I created the image_compare package to calculate differences between two images. There is a variety of algorithms to achieve this task such as percentage difference from overlaying images, euclid. color distance, RGB histogram comparison, and hashing comparison such as perceptual hash.
Here's quick example:
import 'package:image_compare/image_compare.dart';
// ...
Future<double> compare() async {
var a = File('../images/tiger.jpg');
var b = Uri.parse('https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample- images03.jpg');
return compareImages(src1: a, src2: b);
}
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With