当前位置: 首页>>代码示例>>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;未经允许,请勿转载。