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


Python Image.NEAREST屬性代碼示例

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


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

示例1: expand

# 需要導入模塊: import Image [as 別名]
# 或者: from Image import NEAREST [as 別名]
def expand(image, border=0, fill=0):
    "Add border to image"
    left, top, right, bottom = _border(border)
    width = left + image.size[0] + right
    height = top + image.size[1] + bottom
    out = Image.new(image.mode, (width, height), _color(fill, image.mode))
    out.paste(image, (left, top))
    return out

##
# Returns a sized and cropped version of the image, cropped to the
# requested aspect ratio and size.
# <p>
# The <b>fit</b> function was contributed by Kevin Cazabon.
#
# @param size The requested output size in pixels, given as a
#     (width, height) tuple.
# @param method What resampling method to use.  Default is Image.NEAREST.
# @param bleed Remove a border around the outside of the image (from all
#     four edges.  The value is a decimal percentage (use 0.01 for one
#     percent).  The default value is 0 (no border).
# @param centering Control the cropping position.  Use (0.5, 0.5) for
#     center cropping (e.g. if cropping the width, take 50% off of the
#     left side, and therefore 50% off the right side).  (0.0, 0.0)
#     will crop from the top left corner (i.e. if cropping the width,
#     take all of the crop off of the right side, and if cropping the
#     height, take all of it off the bottom).  (1.0, 0.0) will crop
#     from the bottom left corner, etc. (i.e. if cropping the width,
#     take all of the crop off the left side, and if cropping the height
#     take none from the top, and therefore all off the bottom).
# @return An image. 
開發者ID:awslabs,項目名稱:mxnet-lambda,代碼行數:33,代碼來源:ImageOps.py

示例2: check_image_background

# 需要導入模塊: import Image [as 別名]
# 或者: from Image import NEAREST [as 別名]
def check_image_background(image):
	im = convert_to_bw(image)
	im_smol = im.resize((int(x / 4) for x in im.size), Image.NEAREST)
	pixels = im_smol.getdata()
	black_threshold = 150 # Threshold doesn't really matter as the image is only 0 and 255
	nblack = 0
	n = len(pixels)
	for pixel in pixels:
		if pixel < black_threshold:
			nblack += 1

	if (nblack / float(n)) > 0.5:
		image = invert_image(image) # Invert image if more than half of the bw image is considered black
	return image 
開發者ID:Lynnesbian,項目名稱:OCRbot,代碼行數:16,代碼來源:service.py

示例3: load_imgfile

# 需要導入模塊: import Image [as 別名]
# 或者: from Image import NEAREST [as 別名]
def load_imgfile(self, filename):
		self.currentName = filename
		fullFilename = os.path.join(self.inDir, filename)
		print "Loading " + fullFilename
		img = Image.open(fullFilename)

		self.imageOrig = img
		self.imageOrigSize = (img.size[0], img.size[1])
		print "Image is " + str(self.imageOrigSize[0]) + "x" + str(self.imageOrigSize[1])

		basewidth = 512
		wpercent = (basewidth/float(img.size[0]))
		hsize = int((float(img.size[1])*float(wpercent)))
		if fast_preview:
			#does NOT create a copy so self.imageOrig is the same as self.image
			img.thumbnail((basewidth,hsize), Image.NEAREST)
		else:
			if antialiase_original_preview:
				img = img.resize((basewidth,hsize), Image.ANTIALIAS)
			else:
				img = img.copy()
				img.thumbnail((basewidth,hsize), Image.NEAREST)
		self.image = img
		print "Resized preview"

		#self.geometry("1024x"+str(hsize + 100))
		self.configure(relief='flat', background='gray')

		self.imagePhoto = ImageTk.PhotoImage(self.image)
		self.imageLabel.configure(width=self.imagePhoto.width(), height=self.imagePhoto.height())
		self.imageLabel.create_image(0, 0, anchor=NW, image=self.imagePhoto)

		self.previewPhoto = ImageTk.PhotoImage(self.image)
		self.previewLabel.configure(image=self.previewPhoto)

		self.item = None

		self.verti_aux_item = None
		self.horiz_aux_item = None

		self.on_aspect_changed(None, None, None) #update aspect ratio with new image size

		#self.imageLabel.pack(side = "left", fill = "both", expand = "yes")
		#self.previewLabel.pack(side = "left", fill = "both", expand = "yes")
		#self.c.pack(side = "bottom", fill = "both", expand = "yes")

		#self.c.xview_moveto(0)
		#self.c.yview_moveto(0)
		#self.c.config(scrollregion=self.c.bbox('all')) 
開發者ID:pknowles,項目名稱:cropall,代碼行數:51,代碼來源:cropall.py


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