本文整理匯總了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)
示例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
示例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()
示例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)
示例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)
示例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
示例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')
示例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
示例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
示例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])
示例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')
示例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()
示例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()
示例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]
示例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)