Python Image.BICUBIC Examples
The following are 8
code examples of Image.BICUBIC().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Image
, or try the search function
.
Example #1
Source File: imagenet_data.py From Diffusion-Probabilistic-Models with MIT License | 6 votes |
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)
Example #2
Source File: TestMyself_NEWSVM.py From MTCNN-VGG-face with MIT License | 6 votes |
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) # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
Example #3
Source File: TestMyselfWithMTCNN.py From MTCNN-VGG-face with MIT License | 6 votes |
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) # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
Example #4
Source File: TestMyself_KNN.py From MTCNN-VGG-face with MIT License | 6 votes |
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) # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
Example #5
Source File: GetAffinePic.py From MTCNN-VGG-face with MIT License | 6 votes |
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) # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
Example #6
Source File: TestMyself_Multithreading.py From MTCNN-VGG-face with MIT License | 6 votes |
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) # 根据所给的人脸图像,眼睛坐标位置,偏移比例,输出的大小,来进行裁剪。
Example #7
Source File: utils.py From sphinx-gallery with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: convert_to_lmdb.py From tensorflow-recipes with Apache License 2.0 | 5 votes |
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]