Files
szurubooru/server/szurubooru/tests/func/test_image_hash.py
Shyam Sunder ea675d20cb server/docker: fix missing installation requirements
Furthermore, an update to Pillow has improved the floating-point
precision of the image hash algorithm, requiring minor updates to
the respective unit tests.

See https://github.com/python-pillow/Pillow/pull/4320
2020-06-04 16:38:26 -04:00

27 lines
951 B
Python

import pytest
from szurubooru.func import image_hash
from numpy import array_equal
def test_signature_functions(read_asset, config_injector):
sig1 = image_hash.generate_signature(read_asset('jpeg.jpg'))
sig2 = image_hash.generate_signature(read_asset('jpeg-similar.jpg'))
sig1_repacked = image_hash.unpack_signature(
image_hash.pack_signature(sig1))
sig2_repacked = image_hash.unpack_signature(
image_hash.pack_signature(sig2))
assert array_equal(sig1, sig1_repacked)
assert array_equal(sig2, sig2_repacked)
dist1 = image_hash.normalized_distance([sig1], sig2)
assert abs(dist1[0] - 0.19713075553164386) < 1e-8
dist2 = image_hash.normalized_distance([sig2], sig2)
assert abs(dist2[0]) < 1e-8
words1 = image_hash.generate_words(sig1)
words2 = image_hash.generate_words(sig2)
words_match = sum(word1 == word2 for word1, word2 in zip(words1, words2))
assert words_match == 18