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


Python Image.ANTIALIAS屬性代碼示例

本文整理匯總了Python中PIL.Image.ANTIALIAS屬性的典型用法代碼示例。如果您正苦於以下問題:Python Image.ANTIALIAS屬性的具體用法?Python Image.ANTIALIAS怎麽用?Python Image.ANTIALIAS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在PIL.Image的用法示例。


在下文中一共展示了Image.ANTIALIAS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: displayImageFileOnLCD

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def displayImageFileOnLCD(filename):
    print 'displays ', filename
    title = 'Review Mode'
    # resize/dither to screen resolution and send to LCD
    image = Image.open(filename)
    im_width, im_height = image.size
    if im_width < im_height:
        image = image.rotate(90)
    image.thumbnail(S_SIZE, Image.ANTIALIAS)
    image_sized = Image.new('RGB', S_SIZE, (0, 0, 0))
    image_sized.paste(image,((S_SIZE[0] - image.size[0]) / 2, (S_SIZE[1] - image.size[1]) / 2))
    # draw filename
    draw = ImageDraw.Draw(image_sized)
    font = ImageFont.truetype('arial.ttf', 18)
    draw.rectangle([(0, 0), (115, 22)], fill=(255,255,255), outline=(0,0,0))
    draw.text((2, 2), title, fill='black', font=font)
    draw.rectangle([(279, 217), (399, 239)], fill=(255,255,255), outline=(0,0,0))
    draw.text((290, 218), filename, fill='black', font=font)
    # display on LCD
    image_sized = ImageOps.invert(image_sized)
    image_sized = image_sized.convert('1') # convert image to black and white
    lcd.write(image_sized.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:24,代碼來源:polapizero_03.py

示例2: download_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def download_image(image_id, url, x1, y1, x2, y2, output_dir):
    """Downloads one image, crops it, resizes it and saves it locally."""
    output_filename = os.path.join(output_dir, image_id + '.png')
    if os.path.exists(output_filename):
        # Don't download image if it's already there
        return True
    try:
        # Download image
        url_file = urlopen(url)
        if url_file.getcode() != 200:
            return False
        image_buffer = url_file.read()
        # Crop, resize and save image
        image = Image.open(BytesIO(image_buffer)).convert('RGB')
        w = image.size[0]
        h = image.size[1]
        image = image.crop((int(x1 * w), int(y1 * h), int(x2 * w),
                            int(y2 * h)))
        image = image.resize((299, 299), resample=Image.ANTIALIAS)
        image.save(output_filename)
    except IOError:
        return False
    return True 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:25,代碼來源:download_images.py

示例3: printImageFile

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def printImageFile(filename):
    print 'prints ', filename
    # resize to printer resolution and send to printer
    try:
        image = Image.open(filename)
        im_width, im_height = image.size
        if im_width > im_height:
            image = image.rotate(90)
        image.thumbnail((PRINTER_HEIGHT, PRINTER_WIDTH), Image.ANTIALIAS)
        printer.printImage(image, False)
        printer.justify('C')
        printer.setSize('S')
        printer.println("PolaPi-Zero")
        printer.feed(3)
    except IOError:
        print ("cannot identify image file", filename) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:18,代碼來源:polapizero_07.py

示例4: get_image_scaled

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def get_image_scaled(image):
    # Calculate the aspect ratio of the image
    image_aspect = float(image.size[1]) / float(image.size[0])

    # Scale the image
    image_scaled = (s.WINDOW_WIDTH, int(s.WINDOW_WIDTH * image_aspect))
    
    if image_aspect > 1:
        image_scaled = (int(s.WINDOW_HEIGHT / image_aspect), s.WINDOW_HEIGHT)

    coords = ((s.WINDOW_WIDTH - image_scaled[0])/2,
              (s.WINDOW_HEIGHT - image_scaled[1])/2,
              image_scaled[0], image_scaled[1])

    # Creat the resized image and return it and the co-ordinates.
    return ImageTk.PhotoImage(
        image.resize(image_scaled, Image.ANTIALIAS)), coords

# -----------------------------------------------------------------------------
# Function to output the co-ordinates of the boxes
# ----------------------------------------------------------------------------- 
開發者ID:Humpheh,項目名稱:PiPark,代碼行數:23,代碼來源:setup_selectarea.py

示例5: printImageFile

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def printImageFile(filename):
    print 'prints ', filename
    # resize to printer resolution and send to printer
    try:
        image = Image.open(filename)
        im_width, im_height = image.size
        if im_width > im_height:
            image = image.rotate(90)
        image.thumbnail((P_HEIGHT, P_WIDTH), Image.ANTIALIAS)
        printer.printImage(image, False)
        printer.justify('C')
        printer.setSize('S')
        printer.println("PolaPi-Zero")
        printer.feed(3)
    except IOError:
        print ("cannot identify image file", filename) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:18,代碼來源:polapizero_05.py

示例6: printImageFile

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def printImageFile(filename):
    print 'prints ', filename
    # resize to printer resolution and send to printer
    try:
        image = Image.open(filename)
        im_width, im_height = image.size
        if im_width > im_height:
            image = image.rotate(90, expand=1)
            im_width, im_height = image.size
        ratio = (PRINTER_HEIGHT/float(im_width))
        height = int((float(im_height)*float(ratio)))
        image = image.resize((PRINTER_HEIGHT, height), Image.ANTIALIAS)
        
        printer.printImage(image, False)
        printer.justify('C')
        printer.setSize('S')
        printer.println("PolaPi-Zero")
        printer.feed(3)
    except IOError:
        print ("cannot identify image file", filename) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:22,代碼來源:polapizero_09.py

示例7: get_imgtk

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def get_imgtk(self, img_bgr):
		img = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
		im = Image.fromarray(img)
		imgtk = ImageTk.PhotoImage(image=im)
		wide = imgtk.width()
		high = imgtk.height()
		if wide > self.viewwide or high > self.viewhigh:
			wide_factor = self.viewwide / wide
			high_factor = self.viewhigh / high
			factor = min(wide_factor, high_factor)
			wide = int(wide * factor)
			if wide <= 0 : wide = 1
			high = int(high * factor)
			if high <= 0 : high = 1
			im=im.resize((wide, high), Image.ANTIALIAS)
			imgtk = ImageTk.PhotoImage(image=im)
		return imgtk 
開發者ID:wzh191920,項目名稱:License-Plate-Recognition,代碼行數:19,代碼來源:surface.py

示例8: load_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def load_image(file):
    im = Image.open(file)
    im = im.resize((32, 32), Image.ANTIALIAS)
    im = np.array(im).astype(np.float32)
    # PIL打開圖片存儲順序為H(高度),W(寬度),C(通道)。
    # PaddlePaddle要求數據順序為CHW,所以需要轉換順序。
    im = im.transpose((2, 0, 1))
    # CIFAR訓練圖片通道順序為B(藍),G(綠),R(紅),
    # 而PIL打開圖片默認通道順序為RGB,因為需要交換通道。
    im = im[(2, 1, 0), :, :]  # BGR
    im = im / 255.0
    im = np.expand_dims(im, axis=0)
    return im


# 獲取圖片數據 
開發者ID:yeyupiaoling,項目名稱:LearnPaddle2,代碼行數:18,代碼來源:use_infer_model.py

示例9: image_to_display

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def image_to_display(std_scr, path, login_win_row=0, start=None, length=None):
    """
    Display an image
    """
    login_max_y, login_max_x = std_scr.getmaxyx()
    rows, columns = os.popen('stty size', 'r').read().split()
    if not start:
        start = 2
    if not length:
        length = int(columns) - 2 * start
    i = Image.open(path)
    i = i.convert('RGBA')
    w, h = i.size
    i.load()
    width = min(w, length, login_max_x-1)
    height = int(float(h) * (float(width) / float(w)))
    height //= 2
    i = i.resize((width, height), Image.ANTIALIAS)
    height = min(height, 90, login_max_y-1)
    for y in xrange(height):
        for x in xrange(width):
            p = i.getpixel((x, y))
            r, g, b = p[:3]
            pixel_print(std_scr, login_win_row+y, start+x, rgb2short(r, g, b)) 
開發者ID:tdoly,項目名稱:baidufm-py,代碼行數:26,代碼來源:c_image.py

示例10: possibly_resize

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def possibly_resize(original):
    """
    Resize the jpeg to MAX_PHOTO_SIZE x MAX_PHOTO_SIZE if it's bigger. Otherwise, return as-is.
    """
    if Image is None:
        return original

    img = Image.open(io.BytesIO(original))
    w,h = img.size
    if w <= MAX_PHOTO_SIZE and h <= MAX_PHOTO_SIZE:
        # original is reasonably-sized
        return original

    # resize
    img.thumbnail((MAX_PHOTO_SIZE, MAX_PHOTO_SIZE), Image.ANTIALIAS)

    resize = io.BytesIO()
    img.save(resize, format='jpeg')
    return resize.getvalue() 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:21,代碼來源:photos.py

示例11: gen_thumb_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def gen_thumb_image(self, img_path, thumb_path, width):
        '''
        生成縮略圖 or 展示圖
        '''
        base_path = os.path.dirname(thumb_path)
        if not os.path.exists(base_path):
            os.makedirs(base_path)
        img = ImagePIL.open(img_path)
        if img.size[0] <= width:
            img.save(thumb_path, 'PNG')
            return thumb_path
        width = width
        height = float(width) / img.size[0] * img.size[1]
        img.thumbnail((width, height), ImagePIL.ANTIALIAS)
        img.save(thumb_path, 'PNG')
        return thumb_path 
開發者ID:honmaple,項目名稱:maple-file,代碼行數:18,代碼來源:router.py

示例12: autocrop_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def autocrop_image(image, border = 0):
    from PIL import Image, ImageOps
    size = image.size
    bb_image = image
    bbox = bb_image.getbbox()
    if (size[0] == bbox[2]) and (size[1] == bbox[3]):
        bb_image=bb_image.convert("RGB")
        bb_image = ImageOps.invert(bb_image)
        bbox = bb_image.getbbox()
    image = image.crop(bbox)
    (width, height) = image.size
    width += border * 2
    height += border * 2
    ratio = float(width)/height
    cropped_image = Image.new("RGBA", (width, height), (0,0,0,0))
    cropped_image.paste(image, (border, border))
    #TODO find epg height
    logo_height = 450 / int(ADDON.getSetting('channels.per.page'))
    logo_height = logo_height - 2
    if ADDON.getSetting('program.channel.logo') == "false":
        cropped_image = cropped_image.resize((int(logo_height*ratio), logo_height),Image.ANTIALIAS)
    return cropped_image 
開發者ID:primaeval,項目名稱:script.tvguide.fullscreen,代碼行數:24,代碼來源:utils.py

示例13: autocrop_image

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def autocrop_image(infile,outfile):
    infile = xbmc.translatePath(infile)
    image = Image.open(infile)
    border = 0
    size = image.size
    bb_image = image
    bbox = bb_image.getbbox()
    if (size[0] == bbox[2]) and (size[1] == bbox[3]):
        bb_image=bb_image.convert("RGB")
        bb_image = ImageOps.invert(bb_image)
        bbox = bb_image.getbbox()
    image = image.crop(bbox)
    (width, height) = image.size
    width += border * 2
    height += border * 2
    ratio = float(width)/height
    cropped_image = Image.new("RGBA", (width, height), (0,0,0,0))
    cropped_image.paste(image, (border, border))
    #TODO find epg height
    logo_height = 450 / int(ADDON.getSetting('channels.per.page'))
    logo_height = logo_height - 2
    cropped_image = cropped_image.resize((int(logo_height*ratio), logo_height),Image.ANTIALIAS)
    outfile = xbmc.translatePath(outfile)
    cropped_image.save(outfile) 
開發者ID:primaeval,項目名稱:script.tvguide.fullscreen,代碼行數:26,代碼來源:ResizeLogos.py

示例14: _send_image_channels

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def _send_image_channels(self):
        self.model.eval()
        image_triplets = self._get_image_triplets()
        if self.image_nr is not None:
            image_triplets = image_triplets[:self.image_nr]
        self.model.train()

        for i, image_triplet in enumerate(image_triplets):
            h, w = image_triplet.shape[1:]
            image_glued = np.zeros((h, 3 * w + 20))

            image_glued[:, :w] = image_triplet[0, :, :]
            image_glued[:, (w + 10):(2 * w + 10)] = image_triplet[1, :, :]
            image_glued[:, (2 * w + 20):] = image_triplet[2, :, :]

            pill_image = Image.fromarray((image_glued * 255.).astype(np.uint8))
            h_, w_ = image_glued.shape
            pill_image = pill_image.resize((int(self.image_resize * w_), int(self.image_resize * h_)),
                                           Image.ANTIALIAS)

            neptune.send_image('{} predictions'.format(self.model_name), pill_image) 
開發者ID:neptune-ai,項目名稱:open-solution-salt-identification,代碼行數:23,代碼來源:callbacks.py

示例15: load_generic_text

# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import ANTIALIAS [as 別名]
def load_generic_text(directory):
    '''Generator that yields image raw from the directory.'''
    files = find_files(directory)
    for filename in files:
        pic = _read_image(filename)
        pic = pic.resize((128,128), Image.ANTIALIAS)
        img = np.array(pic)
        print (img)
        img = img.reshape(-1, 1)
        print (img)
        img = img.reshape(128, 128)
        print(img)
        new_img = Image.fromarray(img)
        new_img.save('output_file.jpg')
        
        yield img, filename 
開發者ID:Zeta36,項目名稱:tensorflow-image-wavenet,代碼行數:18,代碼來源:testing.py


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