dmtrKovalenko / dmtrKovalenko/odiff

Comparing with 1x1 pixel image should fail

Open
#120 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Zig
Stars
3.2k
Forks
115
PR merge metrics
No merged PRs in 30d

Description

When comparing a small image against an empty image, the compare unexpectedly considers them equal.

```
$ docker run --rm -v .:/tmp odiff /tmp/dfd86070d024eb67.png /tmp/b8aa7a84660a2e94.png -t 0
Success! Images are equal.
No diff output created.
```

```
$ file dfd86070d024eb67.png
dfd86070d024eb67.png: PNG image data, 1 x 1, 8-bit/color RGB, non-interlaced
```

```
$ file b8aa7a84660a2e94.png
b8aa7a84660a2e94.png: PNG image data, 106 x 106, 8-bit/color RGB, non-interlaced
```

b8aa7a84660a2e94.png:
![Image](https://github.com/user-attachments/assets/d14be83e-7165-40c2-b62a-86b9f9007d6c)

If we set fail-on-layout, it also fails as expected:
```
$ docker run --rm -v .:/tmp odiff /tmp/dfd86070d024eb67.png /tmp/b8aa7a84660a2e94.png -t 0 --fail-on-layout
Failure! Images have different layout.
```

If we resize the 1x1 image, it starts to fail, as expected.

16x16 still doesn't detect the difference
```
$ convert dfd86070d024eb67.png -resize 16x16! output16x16.png
$ docker run --rm -v .:/tmp odiff /tmp/output16x16.png /tmp/b8aa7a84660a2e94.png -t 0 /tmp/diff.png
Success! Images are equal.
```

20x20 starts showing a diff
```
$ convert dfd86070d024eb67.png -resize 20x20! output20x20.png
$ docker run --rm -v .:/tmp odiff /tmp/output20x20.png /tmp/b8aa7a84660a2e94.png -t 0 /tmp/diff.png
Failure! Images are different.
Different pixels: 1 (0.250000%)
```

24x24 diff gets bigger
```
$ convert dfd86070d024eb67.png -resize 24x24! output24x24.png
$ docker run --rm -v .:/tmp odiff /tmp/output24x24.png /tmp/b8aa7a84660a2e94.png -t 0 /tmp/diff.png
Failure! Images are different.
Different pixels: 33 (5.729167%)
```

Looking at the generated diff for a 32x32 and 64x64 image:
![Image](https://github.com/user-attachments/assets/e66da9fc-67fe-44af-8801-58bf82bfbb60)
![Image](https://github.com/user-attachments/assets/949e9343-523d-4bf8-b165-cb5f73dca5be)

The diff images suggest that the bigger image was just cropped? In that case, the remaining section would be equal.

In standard cases, where a few mostly empty lines were added on one side, or the image was slightly resized, I find it very useful that odiff can still produce sensible diffs.
But in these extreme cases, the comparison doesn't really work anymore.

Idea: A workaround (without changing the internal calculations much) could be to add a --layout-threshold param, that fails e.g. if the layout differs by a certain factor.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.