Skip to content

Upgraded dependencies so that other projects can use more up to date libraries #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.gitignore

# Files and directories created by pub
.dart_tool/
.packages
Expand Down
15 changes: 15 additions & 0 deletions .idea/image_compare_2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 1.1.7

- took care of some lints

## 1.1.6

- took care of some lints

## 1.1.5

- took care of some lints

## 1.1.4

- upgraded image dependency and formatted dart

## 1.1.3

- forked as image_compare_2 with up to date dependencies and running example

## 1.1.2

- Handle transparency with alpha channel option
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 dart package: image_compare authors
Copyright 2021-2023 dart packages: image_compare and image_compre_2 authors

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

![image1](https://github.com/nitinramadoss/image_compare/blob/main/images/seven2.PNG) ![image2](https://github.com/nitinramadoss/image_compare/blob/main/images/seven.PNG)

## What's New?
## Why image_compare_2 instead of image_compare?

As a dependency, the great image_compare package was breaking some requirements and updates were not being published.
Thus, it has been updated as image_compare_2.
If image_compare ever becomes more up to date than image_compare_2, please prefer image_compare as it is the original package.

## What was New?
- Handle transparency with the alpha channel option
- Set `ignoreAlpha` to `true` to ignore alpha channel
- Available for EuclideanColorDistance, PixelMatching, and the histogram algorithms
Expand All @@ -14,12 +20,12 @@
Add to pubspec.yaml
```
dependencies:
image_compare: ^1.1.1
image_compare_2: ^1.1.3
```

Import:
```
import 'package:image_compare/image_compare.dart';
import 'package:image_compare_2/image_compare_2.dart';
```

## Classes:
Expand Down Expand Up @@ -51,8 +57,8 @@ var b = Uri.parse('https://hs.sbcounty.gov/cn/Photo%20Gallery/Sample%20Picture%2
```
File example:
```
var a = File('../images/tiger.jpg');
var b = File('../images/leopard.png');
var a = File('images/tiger.jpg');
var b = File('images/leopard.png');
```
Bytes example:
```
Expand Down
28 changes: 16 additions & 12 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import 'dart:io';
import 'package:image/image.dart';
import 'package:image_compare/image_compare.dart';
import 'package:image_compare_2/image_compare_2.dart';

void main(List<String> arguments) async {
var url1 =
'https://www.tompetty.com/sites/g/files/g2000007521/f/sample_01.jpg';
'https://www.tompetty.com/sites/g/files/g2000014681/files/2022-06/TP%2520skateboard%25205.14.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 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 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/objects/red_apple.png'),
File('../images/animals/tiger.jpg')
File('images/animals/bunny.jpg'),
File('images/objects/red_apple.png'),
File('images/animals/tiger.jpg')
];

var networkImages = [
Expand Down Expand Up @@ -54,13 +54,17 @@ void main(List<String> arguments) async {

// Calculate euclidean color distance between two images
var imageResult = await compareImages(
src1: file1, src2: file2, algorithm: EuclideanColorDistance(ignoreAlpha: true));
src1: file1,
src2: file2,
algorithm: EuclideanColorDistance(ignoreAlpha: true));

print('Difference: ${imageResult * 100}%');

// Calculate pixel matching between one network and one asset image
var networkAssetResult =
await compareImages(src1: Uri.parse(url2), src2: image2, algorithm: PixelMatching(tolerance: 0.1));
var networkAssetResult = await compareImages(
src1: Uri.parse(url2),
src2: image2,
algorithm: PixelMatching(tolerance: 0.1));

print('Difference: ${networkAssetResult * 100}%');

Expand Down
2 changes: 1 addition & 1 deletion lib/image_compare.dart → lib/image_compare_2.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library image_compare;
library image_compare_2;

export 'src/algorithms.dart';
export 'src/functions.dart';
48 changes: 25 additions & 23 deletions lib/src/algorithms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:image/image.dart';
/// Abstract class for all algorithms
abstract class Algorithm {
/// [Pair] of [Pixel] lists for [src1] and [src2]
var _pixelListPair;
Pair _pixelListPair = Pair([], []);

/// Default constructor gets implicitly called on subclass instantiation
Algorithm();
Expand Down Expand Up @@ -97,7 +97,7 @@ abstract class DirectAlgorithm extends Algorithm {
/// * Returns percentage difference (0.0 - no difference, 1.0 - 100% difference)
class EuclideanColorDistance extends DirectAlgorithm {
/// Ignores alpha channel when computing difference
var ignoreAlpha;
bool ignoreAlpha;

EuclideanColorDistance({bool this.ignoreAlpha = false});

Expand Down Expand Up @@ -157,15 +157,15 @@ class EuclideanColorDistance extends DirectAlgorithm {
/// * Returns percentage diffence (0.0 - no difference, 1.0 - 100% difference)
class PixelMatching extends DirectAlgorithm {
/// Ignores alpha channel when computing difference
var ignoreAlpha;
bool ignoreAlpha;

/// Percentage tolerance value between 0.0 and 1.0
/// of the range of RGB values, 256, used when directly
/// comparing pixels for equivalence.
///
/// A value of 0.05 means that one RGB value can be + or -
/// (0.05 * 256) of another RGB value.
var tolerance;
double tolerance;

PixelMatching({bool this.ignoreAlpha = false, this.tolerance = 0.05});

Expand Down Expand Up @@ -193,17 +193,17 @@ class PixelMatching extends DirectAlgorithm {
_withinRange(delta, _pixelListPair._first[i]._green,
_pixelListPair._second[i]._green)) {
if (ignoreAlpha ||
_withinRange(delta, _pixelListPair._first[i]._alpha,
_pixelListPair._second[i]._alpha)) {
count++;
}
_withinRange(delta, _pixelListPair._first[i]._alpha,
_pixelListPair._second[i]._alpha)) {
count++;
}
}
}

return 1 - (count / numPixels);
}

bool _withinRange(var delta, var value, var target) {
bool _withinRange(double delta, int value, int target) {
return (target - delta <= value && value <= target + delta);
}

Expand All @@ -229,7 +229,7 @@ class PixelMatching extends DirectAlgorithm {
/// * Returns percentage difference (0.0 - no difference, 1.0 - 100% difference)
class IMED extends DirectAlgorithm {
/// Width parameter of the guassian function
var sigma;
double sigma;

/// Percentage of the smaller image's width representing a
/// component of the window (box) width used for the gaussian blur.
Expand All @@ -240,7 +240,7 @@ class IMED extends DirectAlgorithm {
///
/// Note: Large [blurRatio] values can lead to a long computation time
/// for comparisons.
var blurRatio;
double blurRatio;

IMED({double this.sigma = 1, double this.blurRatio = 0.005});

Expand Down Expand Up @@ -310,12 +310,12 @@ class IMED extends DirectAlgorithm {

/// Helper function to return grayscale value of a pixel
int _grayValue(Pixel p) {
return getLuminanceRgb(p._red, p._green, p._blue);
return getLuminanceRgb(p._red, p._green, p._blue).round();
}

/// Helper function to return distance between two pixels at
/// indices [i] and [j]
double _distance(var i, var j, var width) {
double _distance(int i, int j, int width) {
var distance = 0.0;
var pointA = Pair((i % width), (i / width));
var pointB = Pair((j % width), (j / width));
Expand Down Expand Up @@ -602,10 +602,10 @@ class MedianHash extends HashAlgorithm {
/// Abstract class for all histogram algorithms
abstract class HistogramAlgorithm extends Algorithm {
/// Number of bins in each histogram
var _binSize;
int _binSize = 256;

/// Normalized histograms for [src1] and [src2] stored in a [Pair]
var _histograms;
Pair _histograms = Pair(RGBAHistogram(256), RGBAHistogram(256));

/// Default constructor gets implicitly called on subclass instantiation
HistogramAlgorithm() {
Expand Down Expand Up @@ -650,7 +650,7 @@ abstract class HistogramAlgorithm extends Algorithm {
/// Organizational class for storing [src1] and [src2] data.
/// Fields are RGBA histograms (256 element lists)
class RGBAHistogram {
final _binSize;
final int _binSize;
late List redHist;
late List greenHist;
late List blueHist;
Expand All @@ -660,7 +660,7 @@ class RGBAHistogram {
redHist = List.filled(_binSize, 0.0);
greenHist = List.filled(_binSize, 0.0);
blueHist = List.filled(_binSize, 0.0);
alphaHist = List.filled(_binSize, 0.0);
alphaHist = List.filled(_binSize, 0.0);
}
}

Expand All @@ -678,7 +678,7 @@ class RGBAHistogram {
/// * Returns percentage difference (0.0 - no difference, 1.0 - 100% difference)
class ChiSquareDistanceHistogram extends HistogramAlgorithm {
/// Ignores alpha channel when computing difference
var ignoreAlpha;
bool ignoreAlpha;

ChiSquareDistanceHistogram({bool this.ignoreAlpha = false});

Expand All @@ -694,8 +694,9 @@ class ChiSquareDistanceHistogram extends HistogramAlgorithm {

sum += _diff(_histograms._first.redHist, _histograms._second.redHist) +
_diff(_histograms._first.greenHist, _histograms._second.greenHist) +
_diff(_histograms._first.blueHist, _histograms._second.blueHist) +
(alphaBit * _diff(_histograms._first.alphaHist, _histograms._second.alphaHist));
_diff(_histograms._first.blueHist, _histograms._second.blueHist) +
(alphaBit *
_diff(_histograms._first.alphaHist, _histograms._second.alphaHist));

return sum / (3 + alphaBit);
}
Expand Down Expand Up @@ -740,7 +741,7 @@ class ChiSquareDistanceHistogram extends HistogramAlgorithm {
/// * Returns percentage diffence (0.0 - no difference, 1.0 - 100% difference)
class IntersectionHistogram extends HistogramAlgorithm {
/// Ignores alpha channel when computing difference
var ignoreAlpha;
bool ignoreAlpha;

IntersectionHistogram({bool this.ignoreAlpha = false});

Expand All @@ -756,8 +757,9 @@ class IntersectionHistogram extends HistogramAlgorithm {

sum += _diff(_histograms._first.redHist, _histograms._second.redHist) +
_diff(_histograms._first.greenHist, _histograms._second.greenHist) +
_diff(_histograms._first.blueHist, _histograms._second.blueHist) +
(alphaBit * _diff(_histograms._first.alphaHist, _histograms._second.alphaHist));
_diff(_histograms._first.blueHist, _histograms._second.blueHist) +
(alphaBit *
_diff(_histograms._first.alphaHist, _histograms._second.alphaHist));

return 1 - (sum / (3 + alphaBit));
}
Expand Down
Loading