fix(test): phash 'far' case needs structured images — solid colors phash-collapse
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,18 @@ def _img(color, size=(64, 64)):
|
|||||||
return Image.new("RGB", size, color)
|
return Image.new("RGB", size, color)
|
||||||
|
|
||||||
|
|
||||||
|
def _split(orient, size=64):
|
||||||
|
"""A structured image (half black / half white) so it has real DCT
|
||||||
|
content — solid colors all phash-collapse to the same value."""
|
||||||
|
im = Image.new("L", (size, size), 0)
|
||||||
|
px = im.load()
|
||||||
|
for y in range(size):
|
||||||
|
for x in range(size):
|
||||||
|
if (x if orient == "v" else y) >= size // 2:
|
||||||
|
px[x, y] = 255
|
||||||
|
return im.convert("RGB")
|
||||||
|
|
||||||
|
|
||||||
def test_compute_phash_stable_and_hex():
|
def test_compute_phash_stable_and_hex():
|
||||||
h1 = compute_phash(_img((10, 120, 200)))
|
h1 = compute_phash(_img((10, 120, 200)))
|
||||||
h2 = compute_phash(_img((10, 120, 200)))
|
h2 = compute_phash(_img((10, 120, 200)))
|
||||||
@@ -22,8 +34,9 @@ def test_compute_phash_none_for_non_image():
|
|||||||
|
|
||||||
|
|
||||||
def test_find_similar_none_when_far():
|
def test_find_similar_none_when_far():
|
||||||
new = compute_phash(_img((0, 0, 0)))
|
# Vertical vs horizontal split = structurally orthogonal → far apart.
|
||||||
cand = (compute_phash(_img((255, 255, 255))), 100, 100, 7)
|
new = compute_phash(_split("v"))
|
||||||
|
cand = (compute_phash(_split("h")), 100, 100, 7)
|
||||||
rel, mid = find_similar(new, 50, 50, [cand], threshold=2)
|
rel, mid = find_similar(new, 50, 50, [cand], threshold=2)
|
||||||
assert rel == "none" and mid is None
|
assert rel == "none" and mid is None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user