Skip to content
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

PerceptualHash algorithm produces same results on different images. #16

Open
ChurikiTenna opened this issue Nov 5, 2024 · 0 comments
Open

Comments

@ChurikiTenna
Copy link

ChurikiTenna commented Nov 5, 2024

Sometime algorithm: PerceptualHash() produces the exact same results on different images.
Is this expected behavior?

Log:
flutter: 2.png and 1.png
flutter: PerceptualHash: 39.0625%
flutter: 3.png and 1.png
flutter: PerceptualHash: 19.140625%
flutter: 4.png and 1.png
flutter: PerceptualHash: 39.0625% <= same as 2.png
flutter: 5.png and 1.png
flutter: PerceptualHash: 47.265625%

Code:

for (var i = 1; i < 6; i++) {
        ByteData data = await rootBundle.load('lib/images/$i.png');
        Uint8List bytes = data.buffer.asUint8List();
        img.Image image = img.decodeImage(bytes)!;
        if (img1 != null) {
          debugPrint('$i.png and 1.png');
          await imageCompareTest(img1, image);
        }
        img1 = image;
      }

imageCompareTest(img.Image img1, img.Image img2) async {
  Directory tempDir = await getTemporaryDirectory();

  var url1 = '${tempDir.path}/file1.png';
  var url2 = '${tempDir.path}/file2.png';

// it's a bit redundant but crucial for our use-case
  Uint8List bytes1 = Uint8List.fromList(img.encodePng(img1));
  Uint8List bytes2 = Uint8List.fromList(img.encodePng(img2));

  var file1 = File(url1);
  await file1.writeAsBytes(bytes1);
  var file2 = File(url2);
  await file2.writeAsBytes(bytes2);

  var assetResults = await listCompare(
    target: file1,
    list: [
      file2
    ],
    algorithm: PerceptualHash(),
  );

  for (var e in assetResults) {
    print('PerceptualHash: ${e * 100}%');
  }
}

Images used:
1.png
1
2.png
2
3.png
3
4.png
4
5.png
5

@ChurikiTenna ChurikiTenna changed the title PerceptualHash algorithm produces same result on different images. PerceptualHash algorithm produces same results on different images. Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant