当前位置: 首页>>代码示例>>Python>>正文


Python Image.ANTIALIAS属性代码示例

本文整理汇总了Python中Image.ANTIALIAS属性的典型用法代码示例。如果您正苦于以下问题:Python Image.ANTIALIAS属性的具体用法?Python Image.ANTIALIAS怎么用?Python Image.ANTIALIAS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在Image的用法示例。


在下文中一共展示了Image.ANTIALIAS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def handle(self, *args, **options):
        size = 128, 128
        logging.info("Building avatar thumbnails")
        for infile in glob("servo/uploads/avatars/*.jpg"):
            logging.info(infile)
            im = Image.open(infile)
            im.thumbnail(size, Image.ANTIALIAS)
            im.save(infile, "JPEG")

        logging.info("Cleaning up unused attachments")
        for infile in glob("servo/uploads/attachments/*"):
            fn = infile.decode('utf-8')
            fp = os.path.join("attachments", os.path.basename(fn))
            try:
                Attachment.objects.get(content=fp)
            except Attachment.DoesNotExist:
                os.remove(infile) 
开发者ID:fpsw,项目名称:Servo,代码行数:19,代码来源:cleanup.py

示例2: loadImage

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def loadImage():
    xt = np.zeros((num_img, 3, 96, 96), dtype='float32')
    i = 0
    for file in glob.glob(url+"*.jpg"):   
        img = Image.open(file)  
        img = ImageOps.fit(img, (96, 96), Image.ANTIALIAS)
        img = np.asarray(img, dtype = 'float32') / 255.       
        if(cmp(img.shape , (96,96,3)) == 0):
            img = img.transpose(2,0,1).reshape(3, 96, 96)
            xt[i]=img
        else:
            aux=to_rgb(img)
            aux = aux.transpose(2,0,1).reshape(3, 96, 96)
            xt[i]=aux
        i = i + 1
        return xt 
开发者ID:imatge-upc,项目名称:saliency-2016-cvpr,代码行数:18,代码来源:demo.py

示例3: loadiSUNTest

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def loadiSUNTest():    
    NumSample = 2000
    names = loadNameListSUN(MAT_TEST_SUN,NumSample,'testing')
    Xt = np.zeros((NumSample, 3, 96, 96), dtype='float32')
    for i in range(NumSample):
        img = Image.open('/imatge/jpan/work/iSUN/images/'+names[i]+'.jpg')
        img = ImageOps.fit(img, (96, 96), Image.ANTIALIAS)
        img = np.asarray(img, dtype = 'float32') / 255.
        
        if(cmp(img.shape , (96,96,3)) == 0):
            img = img.transpose(2,0,1).reshape(3, 96, 96)
            Xt[i] = img
        else:
            print names[i]
            aux=to_rgb(img)
            aux = aux.transpose(2,0,1).reshape(3, 96, 96)
            Xt[i]=aux
            
    data_to_save = Xt
    f = file('data_iSUN_Test.cPickle', 'wb')
    pickle.dump(data_to_save, f, protocol=pickle.HIGHEST_PROTOCOL)
    f.close() 
开发者ID:imatge-upc,项目名称:saliency-2016-cvpr,代码行数:24,代码来源:preprocessing.py

示例4: render_to_file

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def render_to_file(fname):
    alt_texture.clear()
    base.graphicsEngine.renderFrame()
    base.graphicsEngine.renderFrame()
    #base.graphicsEngine.extractTextureData(tex, base.win.getGsg())
    #tex = alt_buffer.getTexture()
    pnm = PNMImage()
    #base.win.getScreenshot(pnm)
    alt_texture.store(pnm)
    ss = StringStream()
    pnm.write(ss, 'pnm')
    sio = StringIO.StringIO(ss.getData())
    img = Image.open(sio)
    # poor man's antialiasing
    img = img.resize((WIDTH, HEIGHT), Image.ANTIALIAS)
    img.save(fname) 
开发者ID:dimatura,项目名称:seeing3d,代码行数:18,代码来源:render.py

示例5: resize

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def resize(): # for resizing images to 256 by 256  and zooming in on the objects 
	for s in wanted_classes: 
		files = glob('data/overlays/' + labels[s]+'/*') 
		for f in tqdm(files):
			images = glob(f+'/*')
			for im in images:
				# here I am maintianing the origional images and renaming them with a large_ prefix 
				actual = im
				new = f+'/orig_' + im.split('/')[-1]
				shutil.move(actual,new)
				im = Image.open(new)
				x,y = im.size
				diff = (x-y)/2
				im = im.crop((diff+100,100, x-diff-100, y-100)) # getting a square aspect ratio and zooming in on object by 100 pixels 
				im = ImageOps.fit(im, (256,256), Image.ANTIALIAS) # reshaping to 256 by 256 
				im.save(actual) 
开发者ID:EdwardSmith1884,项目名称:3D-IWGAN,代码行数:18,代码来源:DataSetPrep.py

示例6: getResizedImage

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def getResizedImage(self, filePath, width = None, height = None):
		if not width and not height:
			return filePath

		base, name = os.path.split(filePath)
		path = os.path.join(base, '.' + str(width) + 'x' + str(height) + '_' + name)

		if not os.path.isfile(path):
			os.makedirs(base, exist_ok=True)
			im = Image.open(filePath)
			ar = im.size[0] / im.size[1]
			if height == None:
				height = int(width / ar)
			elif width == None:
				width = int(height * ar)

			out = im.resize((width, height), Image.ANTIALIAS)
			out.save(path, quality=100)

		return path 
开发者ID:julesontheroad,项目名称:NSC_BUILDER,代码行数:22,代码来源:Title.py

示例7: make_thumbnail

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def make_thumbnail(in_fname, out_fname, width, height):
    """Make a thumbnail with the same aspect ratio centered in an
       image with a given width and height
    """
    # local import to avoid testing dependency on PIL:
    try:
        from PIL import Image
    except ImportError:
        import Image
    img = Image.open(in_fname)
    width_in, height_in = img.size
    scale_w = width / float(width_in)
    scale_h = height / float(height_in)

    if height_in * scale_w <= height:
        scale = scale_w
    else:
        scale = scale_h

    width_sc = int(round(scale * width_in))
    height_sc = int(round(scale * height_in))

    # resize the image
    img.thumbnail((width_sc, height_sc), Image.ANTIALIAS)

    # insert centered
    thumb = Image.new('RGB', (width, height), (255, 255, 255))
    pos_insert = ((width - width_sc) // 2, (height - height_sc) // 2)
    thumb.paste(img, pos_insert)

    thumb.save(out_fname)
    # Use optipng to perform lossless compression on the resized image if
    # software is installed
    if os.environ.get('SKLEARN_DOC_OPTIPNG', False):
        try:
            subprocess.call(["optipng", "-quiet", "-o", "9", out_fname])
        except Exception:
            warnings.warn('Install optipng to reduce the size of the generated images') 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:40,代码来源:gen_rst.py

示例8: resizeTile

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def resizeTile(index, size):
    """Apply Antialiasing resizing to tile"""
    resized = tiles[index].resize(size, Image.ANTIALIAS)
    return sImage(resized.tostring(), resized.size, resized.mode)


# Generate image tiles on every workers 
开发者ID:soravux,项目名称:scoop,代码行数:9,代码来源:image_resize.py

示例9: clamp

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def clamp(x, a, b):
	return min(max(x, a), b)

# open a SPIDER image and convert to byte format
#im = Image.open(allImages[0])
#im = im.resize((250, 250), Image.ANTIALIAS)

#root = Tkinter.Tk()
# A root window for displaying objects

# Convert the Image object into a TkPhoto object
#tkimage = ImageTk.PhotoImage(im)

#Tkinter.Label(root, image=tkimage).pack()
# Put it in the display window 
开发者ID:pknowles,项目名称:cropall,代码行数:17,代码来源:cropall.py

示例10: update_preview

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def update_preview(self, widget):
		if self.item:
			#get a crop for the preview
			#box = tuple((int(round(v)) for v in widget.coords(self.item)))
			box = self.getRealBox()
			pbox = self.getPreviewBox()
			if fast_preview:
				preview = self.image.crop(pbox) # region of interest
			else:
				preview = self.imageOrig.crop(box) # region of interest

			#add black borders for correct aspect ratio
			#if preview.size[0] > 512:
			preview.thumbnail(self.image.size, Image.ANTIALIAS) #downscale to preview rez
			paspect = preview.size[0]/float(preview.size[1])
			aspect = self.image.size[0]/float(self.image.size[1])
			if paspect < aspect:
				bbox = (0, 0, int(preview.size[1] * aspect), preview.size[1])
			else:
				bbox = (0, 0, preview.size[0], int(preview.size[0] / aspect))
			preview = ImageOps.expand(preview, border=((bbox[2]-preview.size[0])//2, (bbox[3]-preview.size[1])//2))
			#preview = ImageOps.fit(preview, size=self.image.size, method=Image.ANTIALIAS, bleed=-10.0)

			#resize to preview rez (if too small)
			self.preview = preview.resize(self.image.size, Image.ANTIALIAS)
			self.previewPhoto = ImageTk.PhotoImage(self.preview)
			self.previewLabel.configure(image=self.previewPhoto)

			print str(box[2]-box[0])+"x"+str(box[3]-box[1])+"+"+str(box[0])+"+"+str(box[1]) 
开发者ID:pknowles,项目名称:cropall,代码行数:31,代码来源:cropall.py

示例11: imageResize

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def imageResize(img, username):
    '''
    Image resize to 58 * 58;
    :param img:
    :return:
    '''
    try:
        standard_size = (58, 58)
        file_type = '.jpg'
        user_pic_list = [username, file_type]
        log.debug(str(user_pic_list))
        user_pic_str = ''.join(user_pic_list)
        log.debug('37')
        log.debug('user_pic_path: %s' % str(settings.STATICFILES_DIRS))
        user_pic_path = os.path.join(settings.STATICFILES_DIRS[0], 'img', user_pic_str)
        im = Image.open(img)
        im_new = im.resize(standard_size, Image.ANTIALIAS)
        im_new.save(user_pic_path, 'JPEG', quality=100)
        log.info('The user pic resize successed')
        try:
            all_static = settings.STATIC_ROOT
            all_static_url = os.path.join(all_static, 'img')
        except AttributeError, e:
            all_static_url = ''
            log.info('The config settings.py no STATIC_ROOT attribute')
        if all_static_url and os.path.exists(all_static_url):
            shutil.copy(user_pic_path, all_static_url)
            log.info('The user picture copy to all_static_url')
        else:
            log.debug('The all_static_url is None or do not exist') 
开发者ID:Hasal,项目名称:dzhops,代码行数:32,代码来源:views.py

示例12: loadSUN

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def loadSUN():
    NumSample = 6000;
    X1 = np.zeros((NumSample, 3, 96, 96), dtype='float32')
    y1 = np.zeros((NumSample,48*48), dtype='float32')

    names = loadNameListSUN(MAT_TRAIN_SUN,NumSample,'training')
    for i in range(NumSample):
        img = Image.open('/imatge/jpan/work/iSUN/images/'+names[i]+'.jpg')
        img = ImageOps.fit(img, (96, 96), Image.ANTIALIAS)
        img = np.asarray(img, dtype = 'float32') /255.

        if(cmp(img.shape , (96,96,3)) == 0):
            img = img.transpose(2,0,1).reshape(3, 96, 96)
            X1[i] = img
        else:
            print names[i]
            aux=to_rgb(img)
            aux = aux.transpose(2,0,1).reshape(3, 96, 96)
            X1[i]=aux
            
        label = loadSaliencyMapSUN(names[i])
        label = misc.imresize(label,(48,48)) / 127.5
        label = label -1.
        y1[i] =  label.reshape(1,48*48)  
  
    data_to_save = (X1, y1)
    f = file('data_iSun_T.cPickle', 'wb')
    pickle.dump(data_to_save, f, protocol=pickle.HIGHEST_PROTOCOL)
    f.close() 
开发者ID:imatge-upc,项目名称:saliency-2016-cvpr,代码行数:31,代码来源:preprocessing.py

示例13: loadiSUNVAL

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def loadiSUNVAL():
    NumSample = 926;
    X2 = np.zeros((NumSample, 3, 96, 96), dtype='float32')
    y2 = np.zeros((NumSample,48*48), dtype='float32')
    names = loadNameListSUN(MAT_VAL_SUN,NumSample,'validation')
    for i in range(NumSample):
        img = Image.open('/imatge/jpan/work/iSUN/images/'+names[i]+'.jpg')
        img = ImageOps.fit(img, (96, 96), Image.ANTIALIAS)
        img = np.asarray(img, dtype = 'float32') /255.

        if(cmp(img.shape , (96,96,3)) == 0):
            img = img.transpose(2,0,1).reshape(3, 96, 96)
            X2[i] = img
        else:
            print names[i]
            aux=to_rgb(img)
            aux = aux.transpose(2,0,1).reshape(3, 96, 96)
            X2[i]=aux
            
        label = loadSaliencyMapSUN(names[i])
        label = misc.imresize(label,(48,48)) / 127.5
        label = label -1.
        y2[i] =  label.reshape(1,48*48)    
  
    data_to_save = (X2, y2)
    f = file('data_iSun_VAL.cPickle', 'wb')
    pickle.dump(data_to_save, f, protocol=pickle.HIGHEST_PROTOCOL)
    f.close() 
开发者ID:imatge-upc,项目名称:saliency-2016-cvpr,代码行数:30,代码来源:preprocessing.py

示例14: create_thumb

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def create_thumb(self,im):
    
        x = 800
        y = 800
        size = (y,x)
        image = Image.fromarray(im)
        
        image.thumbnail(size, Image.ANTIALIAS)
        background = Image.new('RGBA', size, "black")
        background.paste(image, ((size[0] - image.size[0]) / 2, (size[1] - image.size[1]) / 2))
        
        return np.array(background)[:,:,0:3] 
开发者ID:imatge-upc,项目名称:retrieval-2016-deepvision,代码行数:14,代码来源:vis.py

示例15: make_thumbnail

# 需要导入模块: import Image [as 别名]
# 或者: from Image import ANTIALIAS [as 别名]
def make_thumbnail(in_fname, out_fname, width, height):
    """Make a thumbnail with the same aspect ratio centered in an
       image with a given width and height
    """
    img = Image.open(in_fname)
    width_in, height_in = img.size
    scale_w = width / float(width_in)
    scale_h = height / float(height_in)

    if height_in * scale_w <= height:
        scale = scale_w
    else:
        scale = scale_h

    width_sc = int(round(scale * width_in))
    height_sc = int(round(scale * height_in))

    # resize the image
    img.thumbnail((width_sc, height_sc), Image.ANTIALIAS)

    # insert centered
    thumb = Image.new('RGB', (width, height), (255, 255, 255))
    pos_insert = ((width - width_sc) / 2, (height - height_sc) / 2)
    thumb.paste(img, pos_insert)

    thumb.save(out_fname) 
开发者ID:nguy,项目名称:artview,代码行数:28,代码来源:gen_rst.py


注:本文中的Image.ANTIALIAS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。