mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
test new assert_image_similar implementation
This commit is contained in:
parent
8784037463
commit
8967a20ad7
|
@ -7,6 +7,18 @@ import tempfile
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from PIL import Image, ImageMath
|
||||||
|
|
||||||
|
|
||||||
|
def convert_to_comparable(a, b):
|
||||||
|
new_a, new_b = a, b
|
||||||
|
if a.mode == 'P':
|
||||||
|
new_a = Image.new('L', a.size)
|
||||||
|
new_b = Image.new('L', b.size)
|
||||||
|
new_a.putdata(a.getdata())
|
||||||
|
new_b.putdata(b.getdata())
|
||||||
|
return new_a, new_b
|
||||||
|
|
||||||
|
|
||||||
class PillowTestCase(unittest.TestCase):
|
class PillowTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@ -88,6 +100,16 @@ class PillowTestCase(unittest.TestCase):
|
||||||
except:
|
except:
|
||||||
for abyte, bbyte in zip(a.tobytes(), b.tobytes()):
|
for abyte, bbyte in zip(a.tobytes(), b.tobytes()):
|
||||||
diff += abs(abyte-bbyte)
|
diff += abs(abyte-bbyte)
|
||||||
|
|
||||||
|
a, b = convert_to_comparable(a, b)
|
||||||
|
|
||||||
|
new_diff = 0
|
||||||
|
for ach, bch in zip(a.split(), b.split()):
|
||||||
|
chdiff = ImageMath.eval("abs(a - b)", a=ach, b=bch).convert('L')
|
||||||
|
new_diff += sum(i * num for i, num in enumerate(chdiff.histogram()))
|
||||||
|
|
||||||
|
self.assertEqual(diff, new_diff)
|
||||||
|
|
||||||
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
ave_diff = float(diff)/(a.size[0]*a.size[1])
|
||||||
self.assertGreaterEqual(
|
self.assertGreaterEqual(
|
||||||
epsilon, ave_diff,
|
epsilon, ave_diff,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user