v1.1.2image_compare
用於影像比較的 Dart 套件。使用多種演算法比較影像差異。
50喜歡 3350近 30 天下載140Pub 分數
AndroidiOSmacOSWindowsLinux
用於比較圖像的 Dart 套件。透過多種圖像比較技術找出兩張圖像之間的差異。
^3.0.0^2.0.0^1.9.0以下為英文專案原文快照,最新內容請造訪 GitHub。
image1 image2
ignoreAlpha to true to ignore alpha channelPixelMatching(ignoreAlpha: true);Add to pubspec.yaml
dependencies:
image_compare: ^1.1.1
Import:
import 'package:image_compare/image_compare.dart';
Pixel Comparison Algorithms
PixelMatching({bool ignoreAlpha = true, double tolerance = 0.05})EuclideanColorDistance({bool ignoreAlpha = true})IMED({double sigma = 1, double blurRatio = 0.005})Histogram Comparison Algorithms
ChiSquareDistanceHistogram({bool ignoreAlpha = true})IntersectionHistogram({bool ignoreAlpha = true})Hashing Comparison Algorithms
PerceptualHash()AverageHash()MedianHash()Url example:
var a = Uri.parse('https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg');
var b = Uri.parse('https://hs.sbcounty.gov/cn/Photo%20Gallery/Sample%20Picture%20-%20Koala.jpg');
File example:
var a = File('../images/tiger.jpg');
var b = File('../images/leopard.png');
Bytes example:
var a = [50, 183, 24, ...];
var b = [255, 230, 81, ...];
Image example:
var a = Image(100, 100);
var b = Image.from(a);
Any combination example:
var a = File('../images/tiger.jpg');
var b = Uri.parse('https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg');
PixelMatching()var result = await compareImages(src1: a, src2: b, algorithm: ChiSquareDistanceHistogram())
// or compare one image source to a list of others
var results = await listCompare(target: a, list: [a, b], algorithm: IMED(blurRatio: 0.1));
All algorithms return percentage difference (0.0 - no difference, 1.0 - 100% difference), but their meanings are different
PixelMatching({double tolerance = 0.05})EuclideanColorDistance()IMED({double sigma = 1, double blurRatio = 0.005})Source: IMage Euclidean Distance pdf
ChiSquareDistanceHistogram()IntersectionHistogram()PerceptualHash()Source: HackerFactor article
AverageHash()Source: HackerFactor article
MedianHash()Source: Content-Blockchain article
import 'dart:io';
import 'package:image/image.dart';
import 'package:image_compare/image_compare.dart';
void main(List<String> arguments) async {
var url1 =
'https://www.tompetty.com/sites/g/files/g2000007521/f/sample_01.jpg';
var url2 =
'https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg';
var file1 = File('../images/drawings/kolam1.png');
var file2 = File('../images/drawings/scribble1.png');
var bytes1 = File('../images/animals/koala.jpg').readAsBytesSync();
var bytes2 = File('../images/animals/komodo.jpg').readAsBytesSync();
var image1 = decodeImage(bytes1);
var image2 = decodeImage(bytes2);
var assetImages = [
File('../images/animals/bunny.jpg'),
File('../images/animals/deer.jpg'),
File('../images/animals/tiger.jpg')
];
var networkImages = [
Uri.parse(
'https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg'),
Uri.parse(
'https://hs.sbcounty.gov/cn/Photo%20Gallery/Sample%20Picture%20-%20Koala.jpg'),
Uri.parse(
'https://c.files.bbci.co.uk/12A9B/production/_111434467_gettyimages-1143489763.jpg'),
];
// Calculate chi square histogram distance between two network images
var networkResult = await compareImages(
src1: Uri.parse(url1),
src2: Uri.parse(url2),
algorithm: ChiSquareDistanceHistogram());
print('Difference: ${networkResult * 100}%');
// Calculate IMED between two asset images
var assetResult = await compareImages(
src1: file1, src2: file2, algorithm: IMED(blurRatio: 0.001));
print('Difference: ${assetResult * 100}%');
// Calculate intersection histogram difference between two bytes of images
var byteResult = await compareImages(
src1: bytes1, src2: bytes2, algorithm: IntersectionHistogram());
print('Difference: ${byteResult * 100}%');
// Calculate euclidean color distance between two images
var imageResult = await compareImages(
src1: image1, src2: image2, algorithm: EuclideanColorDistance());
print('Difference: ${imageResult * 100}%');
// Calculate pixel matching between one network and one asset image
var networkAssetResult =
await compareImages(src1: Uri.parse(url2), src2: file1);
print('Difference: ${networkAssetResult * 100}%');
// Calculate median hash between a byte array and image
var byteImageResult =
await compareImages(src1: image1, src2: bytes1, algorithm: MedianHash());
print('Difference: ${byteImageResult * 100}%');
// Calculate average hash difference between a network image
// and a list of network images
var networkResults = await listCompare(
target: Uri.parse(url1),
list: networkImages,
algorithm: AverageHash(),
);
networkResults.forEach((e) => print('Difference: ${e * 100}%'));
// Calculate perceptual hash difference between an asset image
// and a list of asset iamges
var assetResults = await listCompare(
target: File('../images/animals/deer.jpg'),
list: assetImages,
algorithm: PerceptualHash(),
);
assetResults.forEach((e) => print('Difference: ${e * 100}%'));
}