當前位置: 首頁>>代碼示例>>Python>>正文


Python Image.BICUBIC屬性代碼示例

本文整理匯總了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) 
開發者ID:Sohl-Dickstein,項目名稱:Diffusion-Probabilistic-Models,代碼行數:27,代碼來源:imagenet_data.py

示例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)
        # 根據所給的人臉圖像,眼睛坐標位置,偏移比例,輸出的大小,來進行裁剪。 
開發者ID:KaiJin1995,項目名稱:MTCNN-VGG-face,代碼行數:21,代碼來源:TestMyself_NEWSVM.py

示例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)
    # 根據所給的人臉圖像,眼睛坐標位置,偏移比例,輸出的大小,來進行裁剪。 
開發者ID:KaiJin1995,項目名稱:MTCNN-VGG-face,代碼行數:21,代碼來源:GetAffinePic.py

示例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) 
開發者ID:sphinx-gallery,項目名稱:sphinx-gallery,代碼行數:43,代碼來源:utils.py

示例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] 
開發者ID:PatWie,項目名稱:tensorflow-recipes,代碼行數:32,代碼來源:convert_to_lmdb.py


注:本文中的Image.BICUBIC屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。