2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import ImageOps
|
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageOps(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class Deformer:
|
|
|
|
def getmesh(self, im):
|
|
|
|
x, y = im.size
|
|
|
|
return [((0, 0, x, y), (0, 0, x, 0, x, y, y, 0))]
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
deformer = Deformer()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.autocontrast(hopper("L"))
|
|
|
|
ImageOps.autocontrast(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.autocontrast(hopper("L"), cutoff=10)
|
|
|
|
ImageOps.autocontrast(hopper("L"), ignore=[0, 255])
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.colorize(hopper("L"), (0, 0, 0), (255, 255, 255))
|
|
|
|
ImageOps.colorize(hopper("L"), "black", "white")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.crop(hopper("L"), 1)
|
|
|
|
ImageOps.crop(hopper("RGB"), 1)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.deform(hopper("L"), self.deformer)
|
|
|
|
ImageOps.deform(hopper("RGB"), self.deformer)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.equalize(hopper("L"))
|
|
|
|
ImageOps.equalize(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.expand(hopper("L"), 1)
|
|
|
|
ImageOps.expand(hopper("RGB"), 1)
|
|
|
|
ImageOps.expand(hopper("L"), 2, "blue")
|
|
|
|
ImageOps.expand(hopper("RGB"), 2, "blue")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.fit(hopper("L"), (128, 128))
|
|
|
|
ImageOps.fit(hopper("RGB"), (128, 128))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.flip(hopper("L"))
|
|
|
|
ImageOps.flip(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.grayscale(hopper("L"))
|
|
|
|
ImageOps.grayscale(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.invert(hopper("L"))
|
|
|
|
ImageOps.invert(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.mirror(hopper("L"))
|
|
|
|
ImageOps.mirror(hopper("RGB"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.posterize(hopper("L"), 4)
|
|
|
|
ImageOps.posterize(hopper("RGB"), 4)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
ImageOps.solarize(hopper("L"))
|
|
|
|
ImageOps.solarize(hopper("RGB"))
|
2013-07-01 15:36:46 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_1pxfit(self):
|
|
|
|
# Division by zero in equalize if image is 1 pixel high
|
2014-09-05 14:03:56 +04:00
|
|
|
newimg = ImageOps.fit(hopper("RGB").resize((1, 1)), (35, 35))
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(newimg.size, (35, 35))
|
2013-07-01 15:36:46 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
newimg = ImageOps.fit(hopper("RGB").resize((1, 100)), (35, 35))
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(newimg.size, (35, 35))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
newimg = ImageOps.fit(hopper("RGB").resize((100, 1)), (35, 35))
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(newimg.size, (35, 35))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_pil163(self):
|
|
|
|
# Division by zero in equalize if < 255 pixels in image (@PIL163)
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
i = hopper("RGB").resize((15, 16))
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
ImageOps.equalize(i.convert("L"))
|
|
|
|
ImageOps.equalize(i.convert("P"))
|
|
|
|
ImageOps.equalize(i.convert("RGB"))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|