本文整理匯總了Python中PIL.Image.BOX屬性的典型用法代碼示例。如果您正苦於以下問題:Python Image.BOX屬性的具體用法?Python Image.BOX怎麽用?Python Image.BOX使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類PIL.Image
的用法示例。
在下文中一共展示了Image.BOX屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_subsample
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_subsample(self):
# This test shows advantages of the subpixel resizing
# after supersampling (e.g. during JPEG decoding).
im = Image.open("Tests/images/flower.jpg")
self.assertEqual(im.size, (480, 360))
dst_size = (48, 36)
# Reference is cropped image resized to destination
reference = im.crop((0, 0, 473, 353)).resize(dst_size, Image.BICUBIC)
# Image.BOX emulates supersampling (480 / 8 = 60, 360 / 8 = 45)
supersampled = im.resize((60, 45), Image.BOX)
with_box = supersampled.resize(dst_size, Image.BICUBIC,
(0, 0, 59.125, 44.125))
without_box = supersampled.resize(dst_size, Image.BICUBIC)
# error with box should be much smaller than without
self.assert_image_similar(reference, with_box, 6)
with self.assertRaisesRegex(AssertionError, r"difference 29\."):
self.assert_image_similar(reference, without_box, 5)
示例2: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def __init__(self, size, maintain_aspect_ratio=False, resample='bicubic'):
self.size = size
self.maintain_aspect_ratio = maintain_aspect_ratio
resampling_mapping = {
'nearest': Image.NEAREST,
'bilinear': Image.BILINEAR,
'bicubic': Image.BICUBIC,
'lanczos': Image.LANCZOS,
'box': Image.BOX,
'hamming': Image.HAMMING,
}
if resample.lower() not in resampling_mapping.keys():
raise ValueError(
"Unknown resampling method '{}'. Allowed values are '{}'"
.format(resample, "', '".join(resampling_mapping.keys())))
self.resample = resampling_mapping[resample]
super().__init__()
示例3: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def __init__(self, interpolation):
if Image is None:
raise ImportError(
'pillow backend for resize operation requires TensorFlow. Please install it before usage.'
)
self._supported_interpolations = {
'NEAREST': Image.NEAREST,
'NONE': Image.NONE,
'BILINEAR': Image.BILINEAR,
'LINEAR': Image.LINEAR,
'BICUBIC': Image.BICUBIC,
'CUBIC': Image.CUBIC,
'ANTIALIAS': Image.ANTIALIAS,
}
try:
optional_interpolations = {
'BOX': Image.BOX,
'LANCZOS': Image.LANCZOS,
'HAMMING': Image.HAMMING,
}
self._supported_interpolations.update(optional_interpolations)
except AttributeError:
pass
super().__init__(interpolation)
示例4: supported_interpolations
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def supported_interpolations(cls):
if Image is None:
return {}
intrp = {
'NEAREST': Image.NEAREST,
'NONE': Image.NONE,
'BILINEAR': Image.BILINEAR,
'LINEAR': Image.LINEAR,
'BICUBIC': Image.BICUBIC,
'CUBIC': Image.CUBIC,
'ANTIALIAS': Image.ANTIALIAS
}
try:
optional_interpolations = {
'BOX': Image.BOX,
'LANCZOS': Image.LANCZOS,
'HAMMING': Image.HAMMING,
}
intrp.update(optional_interpolations)
except AttributeError:
pass
return intrp
示例5: pixelate
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def pixelate(x, severity=1):
c = [0.6, 0.5, 0.4, 0.3, 0.25][severity - 1]
x = x.resize((int(224 * c), int(224 * c)), PILImage.BOX)
x = x.resize((224, 224), PILImage.BOX)
return x
# mod of https://gist.github.com/erniejunior/601cdf56d2b424757de5
示例6: pixelate
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def pixelate(x, severity=1):
c = [0.95, 0.9, 0.85, 0.75, 0.65][severity - 1]
x = x.resize((int(32 * c), int(32 * c)), PILImage.BOX)
x = x.resize((32, 32), PILImage.BOX)
return x
# mod of https://gist.github.com/erniejunior/601cdf56d2b424757de5
示例7: pixelate
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def pixelate(x, severity=1):
c = [0.9, 0.8, 0.7, 0.6, 0.5][severity - 1]
x = x.resize((int(64 * c), int(64 * c)), PILImage.BOX)
x = x.resize((64, 64), PILImage.BOX)
return x
# mod of https://gist.github.com/erniejunior/601cdf56d2b424757de5
示例8: pixelate
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def pixelate(x, severity=1):
c = [0.5, 0.4, 0.3, 0.25, 0.2][severity - 1]
x = x.resize((int(299 * c), int(299 * c)), PILImage.BOX)
x = x.resize((299, 299), PILImage.BOX)
return x
# mod of https://gist.github.com/erniejunior/601cdf56d2b424757de5
示例9: test_reduce_box
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_reduce_box(self):
for mode in ['RGBX', 'RGB', 'La', 'L']:
case = self.make_case(mode, (8, 8), 0xe1)
case = case.resize((4, 4), Image.BOX)
data = ('e1 e1'
'e1 e1')
for channel in case.split():
self.check_case(channel, self.make_sample(data, (4, 4)))
示例10: test_enlarge_box
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_enlarge_box(self):
for mode in ['RGBX', 'RGB', 'La', 'L']:
case = self.make_case(mode, (2, 2), 0xe1)
case = case.resize((4, 4), Image.BOX)
data = ('e1 e1'
'e1 e1')
for channel in case.split():
self.check_case(channel, self.make_sample(data, (4, 4)))
示例11: test_levels_rgba
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_levels_rgba(self):
case = self.make_levels_case('RGBA')
self.run_levels_case(case.resize((512, 32), Image.BOX))
self.run_levels_case(case.resize((512, 32), Image.BILINEAR))
self.run_levels_case(case.resize((512, 32), Image.HAMMING))
self.run_levels_case(case.resize((512, 32), Image.BICUBIC))
self.run_levels_case(case.resize((512, 32), Image.LANCZOS))
示例12: test_levels_la
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_levels_la(self):
case = self.make_levels_case('LA')
self.run_levels_case(case.resize((512, 32), Image.BOX))
self.run_levels_case(case.resize((512, 32), Image.BILINEAR))
self.run_levels_case(case.resize((512, 32), Image.HAMMING))
self.run_levels_case(case.resize((512, 32), Image.BICUBIC))
self.run_levels_case(case.resize((512, 32), Image.LANCZOS))
示例13: test_dirty_pixels_rgba
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_dirty_pixels_rgba(self):
case = self.make_dirty_case('RGBA', (255, 255, 0, 128), (0, 0, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BOX), (255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BILINEAR),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.HAMMING),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.BICUBIC),
(255, 255, 0))
self.run_dirty_case(case.resize((20, 20), Image.LANCZOS),
(255, 255, 0))
示例14: test_wrong_arguments
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_wrong_arguments(self):
im = hopper()
for resample in (Image.NEAREST, Image.BOX, Image.BILINEAR,
Image.HAMMING, Image.BICUBIC, Image.LANCZOS):
im.resize((32, 32), resample, (0, 0, im.width, im.height))
im.resize((32, 32), resample, (20, 20, im.width, im.height))
im.resize((32, 32), resample, (20, 20, 20, 100))
im.resize((32, 32), resample, (20, 20, 100, 20))
with self.assertRaisesRegex(TypeError,
"must be sequence of length 4"):
im.resize((32, 32), resample, (im.width, im.height))
with self.assertRaisesRegex(ValueError, "can't be negative"):
im.resize((32, 32), resample, (-20, 20, 100, 100))
with self.assertRaisesRegex(ValueError, "can't be negative"):
im.resize((32, 32), resample, (20, -20, 100, 100))
with self.assertRaisesRegex(ValueError, "can't be empty"):
im.resize((32, 32), resample, (20.1, 20, 20, 100))
with self.assertRaisesRegex(ValueError, "can't be empty"):
im.resize((32, 32), resample, (20, 20.1, 100, 20))
with self.assertRaisesRegex(ValueError, "can't be empty"):
im.resize((32, 32), resample, (20.1, 20.1, 20, 20))
with self.assertRaisesRegex(ValueError, "can't exceed"):
im.resize((32, 32), resample, (0, 0, im.width + 1, im.height))
with self.assertRaisesRegex(ValueError, "can't exceed"):
im.resize((32, 32), resample, (0, 0, im.width, im.height + 1))
示例15: test_reduce_filters
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import BOX [as 別名]
def test_reduce_filters(self):
for f in [Image.NEAREST, Image.BOX, Image.BILINEAR,
Image.HAMMING, Image.BICUBIC, Image.LANCZOS]:
r = self.resize(hopper("RGB"), (15, 12), f)
self.assertEqual(r.mode, "RGB")
self.assertEqual(r.size, (15, 12))