本文整理匯總了Python中PIL.Image.LINEAR屬性的典型用法代碼示例。如果您正苦於以下問題:Python Image.LINEAR屬性的具體用法?Python Image.LINEAR怎麽用?Python Image.LINEAR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類PIL.Image
的用法示例。
在下文中一共展示了Image.LINEAR屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_correct_args
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_correct_args(self):
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, 3))
im.im.color_lut_3d('CMYK', Image.LINEAR,
*self.generate_identity_table(4, 3))
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, (2, 3, 3)))
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, (65, 3, 3)))
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, (3, 65, 3)))
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, (3, 3, 65)))
示例2: test_wrong_mode
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_wrong_mode(self):
with self.assertRaisesRegex(ValueError, "wrong mode"):
im = Image.new('L', (10, 10), 0)
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "wrong mode"):
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('L', Image.LINEAR,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "wrong mode"):
im = Image.new('L', (10, 10), 0)
im.im.color_lut_3d('L', Image.LINEAR,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "wrong mode"):
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "wrong mode"):
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(4, 3))
示例3: test_correct_mode
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_correct_mode(self):
im = Image.new('RGBA', (10, 10), 0)
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_identity_table(3, 3))
im = Image.new('RGBA', (10, 10), 0)
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_identity_table(4, 3))
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('HSV', Image.LINEAR,
*self.generate_identity_table(3, 3))
im = Image.new('RGB', (10, 10), 0)
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_identity_table(4, 3))
示例4: test_channels_order
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_channels_order(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
# Reverse channels by splitting and using table
self.assert_image_equal(
Image.merge('RGB', im.split()[::-1]),
im._new(im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2, [
0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 1, 1,
1, 0, 0, 1, 0, 1,
1, 1, 0, 1, 1, 1,
])))
示例5: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [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)
示例6: supported_interpolations
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [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
示例7: test_identities
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_identities(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
# Fast test with small cubes
for size in [2, 3, 5, 7, 11, 16, 17]:
self.assert_image_equal(im, im._new(
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, size))))
# Not so fast
self.assert_image_equal(im, im._new(
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_identity_table(3, (2, 2, 65)))))
示例8: test_copy_alpha_channel
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_copy_alpha_channel(self):
g = Image.linear_gradient('L')
im = Image.merge('RGBA', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180),
g.transpose(Image.ROTATE_270)])
self.assert_image_equal(im, im._new(
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_identity_table(3, 17))))
示例9: test_overflow
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_overflow(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2,
[
-1, -1, -1, 2, -1, -1,
-1, 2, -1, 2, 2, -1,
-1, -1, 2, 2, -1, 2,
-1, 2, 2, 2, 2, 2,
])).load()
self.assertEqual(transformed[0, 0], (0, 0, 255))
self.assertEqual(transformed[50, 50], (0, 0, 255))
self.assertEqual(transformed[255, 0], (0, 255, 255))
self.assertEqual(transformed[205, 50], (0, 255, 255))
self.assertEqual(transformed[0, 255], (255, 0, 0))
self.assertEqual(transformed[50, 205], (255, 0, 0))
self.assertEqual(transformed[255, 255], (255, 255, 0))
self.assertEqual(transformed[205, 205], (255, 255, 0))
transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2,
[
-3, -3, -3, 5, -3, -3,
-3, 5, -3, 5, 5, -3,
-3, -3, 5, 5, -3, 5,
-3, 5, 5, 5, 5, 5,
])).load()
self.assertEqual(transformed[0, 0], (0, 0, 255))
self.assertEqual(transformed[50, 50], (0, 0, 255))
self.assertEqual(transformed[255, 0], (0, 255, 255))
self.assertEqual(transformed[205, 50], (0, 255, 255))
self.assertEqual(transformed[0, 255], (255, 0, 0))
self.assertEqual(transformed[50, 205], (255, 0, 0))
self.assertEqual(transformed[255, 255], (255, 255, 0))
self.assertEqual(transformed[205, 205], (255, 255, 0))
示例10: resize_img
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def resize_img(fname, targ, path, new_path):
dest = os.path.join(path,new_path,str(targ),fname)
if os.path.exists(dest): return
im = Image.open(os.path.join(path, fname)).convert('RGB')
r,c = im.size
ratio = targ/min(r,c)
sz = (scale_to(r, ratio, targ), scale_to(c, ratio, targ))
os.makedirs(os.path.split(dest)[0], exist_ok=True)
im.resize(sz, Image.LINEAR).save(dest)
示例11: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def __init__(self, src_rect, output_size, interp=Image.LINEAR, fill=0):
"""
Args:
src_rect (x0, y0, x1, y1): src coordinates
output_size (h, w): dst image size
interp: PIL interpolation methods
fill: Fill color used when src_rect extends outside image
"""
super().__init__()
self._set_attributes(locals())
示例12: parameters
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def parameters(cls):
parameters = super().parameters()
parameters.update({
'size': NumberField(
value_type=int, optional=True, min_value=1, description="Destination sizes for both dimensions."
),
'dst_width': NumberField(
value_type=int, optional=True, min_value=1, description="Destination width for image resizing."
),
'dst_height': NumberField(
value_type=int, optional=True, min_value=1, description="Destination height for image resizing."
),
'aspect_ratio_scale': StringField(
choices=ASPECT_RATIO_SCALE, optional=True,
description="Allows save image aspect ratio using one of these ways: "
"{}".format(', '.join(ASPECT_RATIO_SCALE))
),
'interpolation': StringField(
choices=_Resizer.all_provided_interpolations(), optional=True, default='LINEAR',
description="Specifies method that will be used."
),
'use_pillow': BoolField(
optional=True, default=False,
description="Parameter specifies usage of Pillow library for resizing."
),
'use_tensorflow': BoolField(
optional=True,
description="Specifies usage of TensorFlow Image for resizing. Requires TensorFlow installation."
),
'resize_realization': StringField(
optional=True, choices=_Resizer.providers,
description="Parameter specifies functionality of which library will be used for resize: "
"{}".format(', '.join(_Resizer.providers))
)
})
return parameters
示例13: resize
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def resize(img, size):
if not isinstance(size, (list, tuple)):
size = (size, size)
if isinstance(img, np.ndarray):
return cv2.resize(img, size)
return img.resize(size, Image.LINEAR)
示例14: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def __init__(self, size, scale_ratios, fix_crop=True, more_fix_crop=True, max_distort=1,
interpolation=Image.LINEAR):
self.height = size[0]
self.width = size[1]
self.scale_ratios = scale_ratios
self.fix_crop = fix_crop
self.more_fix_crop = more_fix_crop
self.max_distort = max_distort
self.interpolation = interpolation
self._crop_scale = None
self._crop_offset = None
self._num_scales = len(scale_ratios)
self._num_offsets = 5 if not more_fix_crop else 13
示例15: test_wrong_args
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LINEAR [as 別名]
def test_wrong_args(self):
im = Image.new('RGB', (10, 10), 0)
with self.assertRaisesRegex(ValueError, "filter"):
im.im.color_lut_3d('RGB',
Image.CUBIC,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "image mode"):
im.im.color_lut_3d('wrong',
Image.LINEAR,
*self.generate_identity_table(3, 3))
with self.assertRaisesRegex(ValueError, "table_channels"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
*self.generate_identity_table(5, 3))
with self.assertRaisesRegex(ValueError, "table_channels"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
*self.generate_identity_table(1, 3))
with self.assertRaisesRegex(ValueError, "table_channels"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
*self.generate_identity_table(2, 3))
with self.assertRaisesRegex(ValueError, "Table size"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
*self.generate_identity_table(3, (1, 3, 3)))
with self.assertRaisesRegex(ValueError, "Table size"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
*self.generate_identity_table(3, (66, 3, 3)))
with self.assertRaisesRegex(ValueError, r"size1D \* size2D \* size3D"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
3, 2, 2, 2, [0, 0, 0] * 7)
with self.assertRaisesRegex(ValueError, r"size1D \* size2D \* size3D"):
im.im.color_lut_3d('RGB',
Image.LINEAR,
3, 2, 2, 2, [0, 0, 0] * 9)
with self.assertRaises(TypeError):
im.im.color_lut_3d('RGB',
Image.LINEAR,
3, 2, 2, 2, [0, 0, "0"] * 8)
with self.assertRaises(TypeError):
im.im.color_lut_3d('RGB',
Image.LINEAR,
3, 2, 2, 2, 16)