本文整理汇总了Python中Image.BICUBIC属性的典型用法代码示例。如果您正苦于以下问题:Python Image.BICUBIC属性的具体用法?Python Image.BICUBIC怎么用?Python Image.BICUBIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Image
的用法示例。
在下文中一共展示了Image.BICUBIC属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_image
# 需要导入模块: import Image [as 别名]
# 或者: from Image import BICUBIC [as 别名]
def load_image(self, idx):
filename = self.X[idx]
import Image
import ImageOps
# print "loading ", self.X[idx]
image = Image.open(self.X[idx])
width, height = image.size
if width > height:
delta2 = int((width - height)/2)
image = ImageOps.expand(image, border=(0, delta2, 0, delta2))
else:
delta2 = int((height - width)/2)
image = ImageOps.expand(image, border=(delta2, 0, delta2, 0))
image = image.resize((self.width, self.width), resample=Image.BICUBIC)
try:
imagenp = np.array(image.getdata()).reshape((self.width,self.width,3))
imagenp = imagenp.transpose((2,0,1)) # move color channels to beginning
except:
# print "reshape failure (black and white?)"
imagenp = self.load_image(np.random.randint(len(self.X)))
return imagenp.astype(theano.config.floatX)
示例2: ScaleRotateTranslate
# 需要导入模块: import Image [as 别名]
# 或者: from Image import BICUBIC [as 别名]
def ScaleRotateTranslate(image, angle, center=None, new_center=None, scale=None, resample=Image.BICUBIC):
if (scale is None) and (center is None):
return image.rotate(angle=angle, resample=resample)
nx, ny = x, y = center
sx = sy = 1.0
if new_center:
(nx, ny) = new_center
if scale:
(sx, sy) = (scale, scale)
cosine = math.cos(angle)
sine = math.sin(angle)
a = cosine / sx
b = sine / sx
c = x - nx * a - ny * b
d = -sine / sy
e = cosine / sy
f = y - nx * d - ny * e
return image.transform(image.size, Image.AFFINE, (a, b, c, d, e, f), resample=resample)
# 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
示例3: ScaleRotateTranslate
# 需要导入模块: import Image [as 别名]
# 或者: from Image import BICUBIC [as 别名]
def ScaleRotateTranslate(image, angle, center=None, new_center=None, scale=None, resample=Image.BICUBIC):
if (scale is None) and (center is None):
return image.rotate(angle=angle, resample=resample)
nx, ny = x, y = center
sx = sy = 1.0
if new_center:
(nx, ny) = new_center
if scale:
(sx, sy) = (scale, scale)
cosine = math.cos(angle)
sine = math.sin(angle)
a = cosine / sx
b = sine / sx
c = x - nx * a - ny * b
d = -sine / sy
e = cosine / sy
f = y - nx * d - ny * e
return image.transform(image.size, Image.AFFINE, (a, b, c, d, e, f), resample=resample)
# 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
示例4: scale_image
# 需要导入模块: import Image [as 别名]
# 或者: from Image import BICUBIC [as 别名]
def scale_image(in_fname, out_fname, max_width, max_height):
"""Scales an image with the same aspect ratio centered in an
image box with the given max_width and max_height
if in_fname == out_fname the image can only be scaled down
"""
# local import to avoid testing dependency on PIL:
Image = _get_image()
img = Image.open(in_fname)
# XXX someday we should just try img.thumbnail((max_width, max_height)) ...
width_in, height_in = img.size
scale_w = max_width / float(width_in)
scale_h = max_height / float(height_in)
if height_in * scale_w <= max_height:
scale = scale_w
else:
scale = scale_h
if scale >= 1.0 and in_fname == out_fname:
return
width_sc = int(round(scale * width_in))
height_sc = int(round(scale * height_in))
# resize the image using resize; if using .thumbnail and the image is
# already smaller than max_width, max_height, then this won't scale up
# at all (maybe could be an option someday...)
img = img.resize((width_sc, height_sc), Image.BICUBIC)
# img.thumbnail((width_sc, height_sc), Image.BICUBIC)
# width_sc, height_sc = img.size # necessary if using thumbnail
# insert centered
thumb = Image.new('RGBA', (max_width, max_height), (255, 255, 255, 255))
pos_insert = ((max_width - width_sc) // 2, (max_height - height_sc) // 2)
thumb.paste(img, pos_insert)
try:
thumb.save(out_fname)
except IOError:
# try again, without the alpha channel (e.g., for JPEG)
thumb.convert('RGB').save(out_fname)
示例5: get_data
# 需要导入模块: import Image [as 别名]
# 或者: from Image import BICUBIC [as 别名]
def get_data(self):
lmdb = "/datasets/celebHQ/celeb_hq.lmdb"
ds = LMDBDataPoint(lmdb, shuffle=True)
ds = ImageDecode(ds, index=0)
ds.reset_state()
resample = Image.BICUBIC
self.remainingImages = ds.size()
for dp in ds.get_data():
# read image
bgr = dp[0]
# convert to Pil Image and resize
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
pil_im = Image.fromarray(rgb)
pil_im = pil_im.resize((self.image_size, self.image_size), resample=resample)
# convert back to opencv fomat
resized = np.array(pil_im)
resized = resized[:, :, ::-1].copy()
# beak for less images
self.remainingImages -= 1
print self.remainingImages
# if (self.remainingImages < 29950):
# break
yield [resized]