mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Add perceptive comparisons to quantization tests
This commit is contained in:
parent
0430a4a834
commit
db989ad99b
|
@ -6,45 +6,46 @@ from PIL import Image
|
||||||
class TestImageQuantize(PillowTestCase):
|
class TestImageQuantize(PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
im = hopper()
|
image = hopper()
|
||||||
|
converted = image.quantize()
|
||||||
|
self.assert_image(converted, 'P', converted.size)
|
||||||
|
self.assert_image_similar(converted.convert('RGB'), image, 10)
|
||||||
|
|
||||||
im = im.quantize()
|
image = hopper()
|
||||||
self.assert_image(im, "P", im.size)
|
converted = image.quantize(palette=hopper('P'))
|
||||||
|
self.assert_image(converted, 'P', converted.size)
|
||||||
im = hopper()
|
self.assert_image_similar(converted.convert('RGB'), image, 60)
|
||||||
im = im.quantize(palette=hopper("P"))
|
|
||||||
self.assert_image(im, "P", im.size)
|
|
||||||
|
|
||||||
def test_libimagequant_quantize(self):
|
def test_libimagequant_quantize(self):
|
||||||
im = hopper()
|
image = hopper()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
im = im.quantize(100, Image.LIBIMAGEQUANT)
|
converted = image.quantize(100, Image.LIBIMAGEQUANT)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
if 'dependency' in str(ex).lower():
|
if 'dependency' in str(ex).lower():
|
||||||
self.skipTest('libimagequant support not available')
|
self.skipTest('libimagequant support not available')
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
self.assert_image(im, "P", im.size)
|
self.assert_image(converted, 'P', converted.size)
|
||||||
|
self.assert_image_similar(converted.convert('RGB'), image, 15)
|
||||||
assert len(im.getcolors()) == 100
|
assert len(converted.getcolors()) == 100
|
||||||
|
|
||||||
def test_octree_quantize(self):
|
def test_octree_quantize(self):
|
||||||
im = hopper()
|
image = hopper()
|
||||||
|
converted = image.quantize(100, Image.FASTOCTREE)
|
||||||
im = im.quantize(100, Image.FASTOCTREE)
|
self.assert_image(converted, 'P', converted.size)
|
||||||
self.assert_image(im, "P", im.size)
|
self.assert_image_similar(converted.convert('RGB'), image, 20)
|
||||||
|
assert len(converted.getcolors()) == 100
|
||||||
assert len(im.getcolors()) == 100
|
|
||||||
|
|
||||||
def test_rgba_quantize(self):
|
def test_rgba_quantize(self):
|
||||||
im = hopper('RGBA')
|
image = hopper('RGBA')
|
||||||
im.quantize()
|
image.quantize()
|
||||||
self.assertRaises(Exception, lambda: im.quantize(method=0))
|
self.assertRaises(Exception, lambda: image.quantize(method=0))
|
||||||
|
|
||||||
def test_quantize(self):
|
def test_quantize(self):
|
||||||
im = Image.open('Tests/images/caption_6_33_22.png')
|
image = Image.open('Tests/images/caption_6_33_22.png').convert('RGB')
|
||||||
im.convert('RGB').quantize().convert('RGB')
|
converted = image.quantize()
|
||||||
|
self.assert_image(converted, 'P', converted.size)
|
||||||
|
self.assert_image_similar(converted.convert('RGB'), image, 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user