本文整理汇总了Python中PIL.Image.CUBIC属性的典型用法代码示例。如果您正苦于以下问题:Python Image.CUBIC属性的具体用法?Python Image.CUBIC怎么用?Python Image.CUBIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类PIL.Image
的用法示例。
在下文中一共展示了Image.CUBIC属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [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)
示例2: supported_interpolations
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [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
示例3: __getitem__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [as 别名]
def __getitem__(self, idx):
name = self.img_name_list[idx]
img = Image.open(os.path.join(self.img_dir, name + '.jpg')).convert("RGB")
mask = Image.open(os.path.join(self.label_dir, name + '.png'))
if self.rescale is not None:
s = self.rescale[0] + random.random() * (self.rescale[1] - self.rescale[0])
adj_size = (round(img.size[0]*s/8)*8, round(img.size[1]*s/8)*8)
img = img.resize(adj_size, resample=Image.CUBIC)
mask = img.resize(adj_size, resample=Image.NEAREST)
if self.img_transform is not None:
img = self.img_transform(img)
if self.mask_transform is not None:
mask = self.mask_transform(mask)
if self.cropsize is not None:
img, mask = imutils.random_crop([img, mask], self.cropsize, (0, 255))
mask = imutils.RescaleNearest(0.125)(mask)
if self.flip is True and bool(random.getrandbits(1)):
img = np.flip(img, 1).copy()
mask = np.flip(mask, 1).copy()
img = np.transpose(img, (2, 0, 1))
return name, img, mask
示例4: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [as 别名]
def __call__(self, image, label):
ratio = random.uniform(self.scale[0], self.scale[1])
w, h = image.size
tw = int(ratio * w)
th = int(ratio * h)
if ratio == 1:
return image, label
elif ratio < 1:
interpolation = Image.ANTIALIAS
else:
interpolation = Image.CUBIC
return image.resize((tw, th), interpolation), \
label.resize((tw, th), Image.NEAREST)
示例5: scale
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [as 别名]
def scale(self, ratio):
w, h = self.shape()
tw = int(ratio * w)
th = int(ratio * h)
if ratio < 1:
interpolation = Image.ANTIALIAS
else:
interpolation = Image.CUBIC
self.data = (self.data).resize((tw, th), interpolation)
示例6: __call__
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [as 别名]
def __call__(self, image, label):
ratio = random.uniform(self.scale[0], self.scale[1])
w, h = image.size
tw = int(ratio * w)
th = int(ratio * h)
if ratio == 1:
return image, label
elif ratio < 1:
interpolation = Image.ANTIALIAS
else:
interpolation = Image.CUBIC
return image.resize((tw, th), interpolation), \
label.resize((tw, th), Image.NEAREST)
示例7: get_screen
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [as 别名]
def get_screen():
screen = env.render(mode='rgb_array').transpose((2, 0, 1)) # transpose into torch order (CHW)
screen = screen[:, 160:320] # Strip off the top and bottom of the screen
# Get cart location
world_width = env.x_threshold * 2
scale = screen_width / world_width
cart_location = int(env.state[0] * scale + screen_width / 2.0) # MIDDLE OF CART
# Decide how much to strip
view_width = 320
if cart_location < view_width // 2:
slice_range = slice(view_width)
elif cart_location > (screen_width - view_width // 2):
slice_range = slice(-view_width, None)
else:
slice_range = slice(cart_location - view_width // 2,
cart_location + view_width // 2)
# Strip off the edges, so that we have a square image centered on a cart
screen = screen[:, :, slice_range]
screen = np.ascontiguousarray(screen, dtype=np.float32) / 255
screen = torch.from_numpy(screen)
resize = T.Compose([T.ToPILImage(),
T.Resize(40, interpolation=Image.CUBIC),
T.ToTensor()])
return resize(screen).unsqueeze(0).to(device) # Resize, and add a batch dimension (BCHW)
示例8: test_wrong_args
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import CUBIC [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)