mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
TestReducingGapResize
This commit is contained in:
parent
b48996c213
commit
a9d7a2be77
|
@ -136,6 +136,93 @@ class TestImagingCoreResize(PillowTestCase):
|
||||||
self.assertRaises(ValueError, self.resize, hopper(), (10, 10), 9)
|
self.assertRaises(ValueError, self.resize, hopper(), (10, 10), 9)
|
||||||
|
|
||||||
|
|
||||||
|
class TestReducingGapResize(PillowTestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
cls.gradients_image = Image.open("Tests/images/radial_gradients.png")
|
||||||
|
cls.gradients_image.load()
|
||||||
|
|
||||||
|
def test_reducing_gap_values(self):
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BICUBIC, reducing_gap=None)
|
||||||
|
im = self.gradients_image.resize((52, 34), Image.BICUBIC)
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self.gradients_image.resize((52, 34), Image.BICUBIC, reducing_gap=0)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
self.gradients_image.resize((52, 34), Image.BICUBIC, reducing_gap=0.99)
|
||||||
|
|
||||||
|
def test_reducing_gap_1(self):
|
||||||
|
for box, epsilon in [
|
||||||
|
(None, 4),
|
||||||
|
((1.1, 2.2, 510.8, 510.9), 4),
|
||||||
|
((3, 10, 410, 256), 10),
|
||||||
|
]:
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BICUBIC, box=box)
|
||||||
|
im = self.gradients_image.resize(
|
||||||
|
(52, 34), Image.BICUBIC, box=box, reducing_gap=1.0
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
self.assert_image_similar(ref, im, epsilon)
|
||||||
|
|
||||||
|
def test_reducing_gap_2(self):
|
||||||
|
for box, epsilon in [
|
||||||
|
(None, 1.5),
|
||||||
|
((1.1, 2.2, 510.8, 510.9), 1.5),
|
||||||
|
((3, 10, 410, 256), 1),
|
||||||
|
]:
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BICUBIC, box=box)
|
||||||
|
im = self.gradients_image.resize(
|
||||||
|
(52, 34), Image.BICUBIC, box=box, reducing_gap=2.0
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
self.assert_image_similar(ref, im, epsilon)
|
||||||
|
|
||||||
|
def test_reducing_gap_3(self):
|
||||||
|
for box, epsilon in [
|
||||||
|
(None, 1),
|
||||||
|
((1.1, 2.2, 510.8, 510.9), 1),
|
||||||
|
((3, 10, 410, 256), .5),
|
||||||
|
]:
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BICUBIC, box=box)
|
||||||
|
im = self.gradients_image.resize(
|
||||||
|
(52, 34), Image.BICUBIC, box=box, reducing_gap=3.0
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
self.assert_image_similar(ref, im, epsilon)
|
||||||
|
|
||||||
|
def test_reducing_gap_8(self):
|
||||||
|
for box in [None, (1.1, 2.2, 510.8, 510.9), (3, 10, 410, 256)]:
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BICUBIC, box=box)
|
||||||
|
im = self.gradients_image.resize(
|
||||||
|
(52, 34), Image.BICUBIC, box=box, reducing_gap=8.0
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
def test_box_filter(self):
|
||||||
|
for box, epsilon in [
|
||||||
|
((0, 0, 512, 512), 5.5),
|
||||||
|
((0.9, 1.7, 128, 128), 9.5),
|
||||||
|
]:
|
||||||
|
ref = self.gradients_image.resize((52, 34), Image.BOX, box=box)
|
||||||
|
im = self.gradients_image.resize(
|
||||||
|
(52, 34), Image.BOX, box=box, reducing_gap=1.0
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assert_image_similar(ref, im, epsilon)
|
||||||
|
|
||||||
|
|
||||||
class TestImageResize(PillowTestCase):
|
class TestImageResize(PillowTestCase):
|
||||||
def test_resize(self):
|
def test_resize(self):
|
||||||
def resize(mode, size):
|
def resize(mode, size):
|
||||||
|
|
|
@ -66,3 +66,30 @@ class TestImageThumbnail(PillowTestCase):
|
||||||
ref = im.resize((32, 32), Image.BICUBIC)
|
ref = im.resize((32, 32), Image.BICUBIC)
|
||||||
# This is still JPEG, some error is present. Without the fix it is 11.5
|
# This is still JPEG, some error is present. Without the fix it is 11.5
|
||||||
self.assert_image_similar(thumb, ref, 1.5)
|
self.assert_image_similar(thumb, ref, 1.5)
|
||||||
|
|
||||||
|
def test_reducing_gap_values(self):
|
||||||
|
im = hopper()
|
||||||
|
im.thumbnail((18, 18), Image.BICUBIC)
|
||||||
|
|
||||||
|
ref = hopper()
|
||||||
|
ref.thumbnail((18, 18), Image.BICUBIC, reducing_gap=2.0)
|
||||||
|
# reducing_gap=2.0 should be the default
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
ref = hopper()
|
||||||
|
ref.thumbnail((18, 18), Image.BICUBIC, reducing_gap=None)
|
||||||
|
with self.assertRaises(AssertionError):
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
||||||
|
self.assert_image_similar(ref, im, 3.5)
|
||||||
|
|
||||||
|
def test_reducing_gap_for_DCT_scaling(self):
|
||||||
|
with Image.open("Tests/images/hopper.jpg") as ref:
|
||||||
|
# thumbnail should call draft with reducing_gap scale
|
||||||
|
ref.draft(None, (18 * 3, 18 * 3))
|
||||||
|
ref = ref.resize((18, 18), Image.BICUBIC)
|
||||||
|
|
||||||
|
with Image.open("Tests/images/hopper.jpg") as im:
|
||||||
|
im.thumbnail((18, 18), Image.BICUBIC, reducing_gap=3.0)
|
||||||
|
|
||||||
|
self.assert_image_equal(ref, im)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user