mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
improve resize test
This commit is contained in:
parent
1321713688
commit
5b8c8aa389
|
@ -148,15 +148,14 @@ class TestImageTransformAffine(PillowTestCase):
|
||||||
im = hopper('RGB')
|
im = hopper('RGB')
|
||||||
return im.crop((10, 20, im.width - 10, im.height - 20))
|
return im.crop((10, 20, im.width - 10, im.height - 20))
|
||||||
|
|
||||||
def _test_rotate(self, angle, transpose):
|
def _test_rotate(self, deg, transpose):
|
||||||
im = self._test_image()
|
im = self._test_image()
|
||||||
|
|
||||||
angle = - math.radians(angle)
|
angle = - math.radians(deg)
|
||||||
matrix = [
|
matrix = [
|
||||||
round(math.cos(angle), 15), round(math.sin(angle), 15), 0.0,
|
round(math.cos(angle), 15), round(math.sin(angle), 15), 0.0,
|
||||||
round(-math.sin(angle), 15), round(math.cos(angle), 15), 0.0,
|
round(-math.sin(angle), 15), round(math.cos(angle), 15), 0.0,
|
||||||
0, 0,
|
0, 0]
|
||||||
]
|
|
||||||
matrix[2] = (1 - matrix[0] - matrix[1]) * im.width / 2
|
matrix[2] = (1 - matrix[0] - matrix[1]) * im.width / 2
|
||||||
matrix[5] = (1 - matrix[3] - matrix[4]) * im.height / 2
|
matrix[5] = (1 - matrix[3] - matrix[4]) * im.height / 2
|
||||||
|
|
||||||
|
@ -164,6 +163,7 @@ class TestImageTransformAffine(PillowTestCase):
|
||||||
transposed = im.transpose(transpose)
|
transposed = im.transpose(transpose)
|
||||||
else:
|
else:
|
||||||
transposed = im
|
transposed = im
|
||||||
|
|
||||||
for resample in [Image.NEAREST, Image.BILINEAR, Image.BICUBIC]:
|
for resample in [Image.NEAREST, Image.BILINEAR, Image.BICUBIC]:
|
||||||
transformed = im.transform(transposed.size, self.transform,
|
transformed = im.transform(transposed.size, self.transform,
|
||||||
matrix, resample)
|
matrix, resample)
|
||||||
|
@ -181,53 +181,55 @@ class TestImageTransformAffine(PillowTestCase):
|
||||||
def test_rotate_270_deg(self):
|
def test_rotate_270_deg(self):
|
||||||
self._test_rotate(270, Image.ROTATE_270)
|
self._test_rotate(270, Image.ROTATE_270)
|
||||||
|
|
||||||
def _test_resize(self, scale):
|
def _test_resize(self, scale, epsilonscale):
|
||||||
im = self._test_image()
|
im = self._test_image()
|
||||||
matrix = [
|
|
||||||
|
size_up = int(round(im.width * scale)), int(round(im.height * scale))
|
||||||
|
matrix_up = [
|
||||||
1 / scale, 0, 0,
|
1 / scale, 0, 0,
|
||||||
0, 1 / scale, 0,
|
0, 1 / scale, 0,
|
||||||
0, 0,
|
0, 0]
|
||||||
]
|
matrix_down = [
|
||||||
size = int(round(im.width * scale)), int(round(im.height * scale))
|
|
||||||
transformed = im.transform(
|
|
||||||
size, self.transform, matrix, Image.NEAREST)
|
|
||||||
matrix = [
|
|
||||||
scale, 0, 0,
|
scale, 0, 0,
|
||||||
0, scale, 0,
|
0, scale, 0,
|
||||||
0, 0,
|
0, 0]
|
||||||
]
|
|
||||||
|
for resample, epsilon in [(Image.NEAREST, 0),
|
||||||
|
(Image.BILINEAR, 2), (Image.BICUBIC, 1)]:
|
||||||
|
transformed = im.transform(
|
||||||
|
size_up, self.transform, matrix_up, resample)
|
||||||
transformed = transformed.transform(
|
transformed = transformed.transform(
|
||||||
im.size, self.transform, matrix, Image.NEAREST)
|
im.size, self.transform, matrix_down, resample)
|
||||||
self.assert_image_equal(im, transformed)
|
self.assert_image_similar(transformed, im, epsilon * epsilonscale)
|
||||||
|
|
||||||
def test_resize_1_1x(self):
|
def test_resize_1_1x(self):
|
||||||
self._test_resize(1.1)
|
self._test_resize(1.1, 6.9)
|
||||||
|
|
||||||
def test_resize_1_5x(self):
|
def test_resize_1_5x(self):
|
||||||
self._test_resize(1.5)
|
self._test_resize(1.5, 5.5)
|
||||||
|
|
||||||
def test_resize_2_0x(self):
|
def test_resize_2_0x(self):
|
||||||
self._test_resize(2.0)
|
self._test_resize(2.0, 5.5)
|
||||||
|
|
||||||
def test_resize_2_3x(self):
|
def test_resize_2_3x(self):
|
||||||
self._test_resize(2.3)
|
self._test_resize(2.3, 3.7)
|
||||||
|
|
||||||
def test_resize_2_5x(self):
|
def test_resize_2_5x(self):
|
||||||
self._test_resize(2.5)
|
self._test_resize(2.5, 3.7)
|
||||||
|
|
||||||
def _test_translate(self, x, y, epsilonscale):
|
def _test_translate(self, x, y, epsilonscale):
|
||||||
im = self._test_image()
|
im = self._test_image()
|
||||||
|
|
||||||
size_up = int(round(im.width + x)), int(round(im.height + y))
|
size_up = int(round(im.width + x)), int(round(im.height + y))
|
||||||
matrix_up = [
|
matrix_up = [
|
||||||
1, 0, -x,
|
1, 0, -x,
|
||||||
0, 1, -y,
|
0, 1, -y,
|
||||||
0, 0,
|
0, 0]
|
||||||
]
|
|
||||||
matrix_down = [
|
matrix_down = [
|
||||||
1, 0, x,
|
1, 0, x,
|
||||||
0, 1, y,
|
0, 1, y,
|
||||||
0, 0,
|
0, 0]
|
||||||
]
|
|
||||||
for resample, epsilon in [(Image.NEAREST, 0),
|
for resample, epsilon in [(Image.NEAREST, 0),
|
||||||
(Image.BILINEAR, 1.5), (Image.BICUBIC, 1)]:
|
(Image.BILINEAR, 1.5), (Image.BICUBIC, 1)]:
|
||||||
transformed = im.transform(
|
transformed = im.transform(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user