本文整理匯總了Python中PIL.Image.LANCZOS屬性的典型用法代碼示例。如果您正苦於以下問題:Python Image.LANCZOS屬性的具體用法?Python Image.LANCZOS怎麽用?Python Image.LANCZOS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類PIL.Image
的用法示例。
在下文中一共展示了Image.LANCZOS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: adjust_house_number_crop
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def adjust_house_number_crop(self, crop, bbox):
max_size = int(self.image_size * self.max_size_per_number)
if crop.width <= max_size and crop.height <= max_size:
return crop, bbox
new_height, new_width = max_size, max_size
if crop.width < max_size:
new_width = crop.width
if crop.height < max_size:
new_height = crop.height
crop = crop.resize((new_width, new_height), Image.LANCZOS)
bbox.width = new_width
bbox.height = new_height
return crop, bbox
示例2: get_cigarette_info
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def get_cigarette_info(self, face_shape, face_width):
"""
獲取當前麵部的煙卷信息
:param face_shape:
:param face_width:
:return:
"""
mouth = face_shape[49:68]
mouth_center = mouth.mean(axis=0).astype("int")
cigarette = self.cigarette.resize(
(face_width, int(face_width * self.cigarette.size[1] / self.cigarette.size[0])),
resample=Image.LANCZOS)
x = mouth[0, 0] - face_width + int(16 * face_width / self.cigarette.size[0])
y = mouth_center[1]
return {"image": cigarette, "pos": (x, y)}
開發者ID:tomoncle,項目名稱:face-detection-induction-course,代碼行數:19,代碼來源:input_static_pic_to_gif2_for_class.py
示例3: turn_into_thumbnail
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def turn_into_thumbnail(file_path, size=None):
"""
Turn given picture into a smaller version.
"""
im = Image.open(file_path)
if size is not None:
(width, height) = size
if height == 0:
size = get_full_size_from_width(im, width)
else:
im = prepare_image_for_thumbnail(im, size)
else:
size = im.size
im = im.resize(size, Image.LANCZOS)
if im.mode == "CMYK":
im = im.convert("RGB")
im.save(file_path, "PNG")
return file_path
示例4: save
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def save(self) -> bool:
if self.model.selection_box is None:
return False
selected_box: Tuple[int, int, int, int] = self.view.get_canvas_object_coords(
self.model.selection_box)
box: Tuple[int, int, int, int] = self.get_real_box(
selected_box, self.model.current_image.size, self.model.canvas_image_dimensions)
new_filename: str = self.find_available_name(
self.model.args.output_dir, self.model.images[self.model.current_file])
saved_image: Image = self.model.current_image.copy().crop(box)
if self.model.args.resize:
saved_image = saved_image.resize(
(self.model.args.resize[0], self.model.args.resize[1]), Image.LANCZOS)
if self.model.args.image_format:
new_filename, _ = os.path.splitext(new_filename)
saved_image.save(os.path.join(self.model.args.output_dir, new_filename),
self.model.args.image_format, quality=self.model.args.image_quality)
self.clear_selection_box()
return True
示例5: download
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def download(pid, image_list, base_url, save_dir, image_size=(512, 512)):
colors = ['red', 'green', 'blue', 'yellow']
for i in tqdm(image_list, postfix=pid):
img_id = i.split('_', 1)
for color in colors:
img_path = img_id[0] + '/' + img_id[1] + '_' + color + '.jpg'
img_name = i + '_' + color + '.png'
img_url = base_url + img_path
# Get the raw response from the url
r = requests.get(img_url, allow_redirects=True, stream=True)
r.raw.decode_content = True
# Use PIL to resize the image and to convert it to L
# (8-bit pixels, black and white)
im = Image.open(r.raw)
im = im.resize(image_size, Image.LANCZOS).convert('L')
im.save(os.path.join(save_dir, img_name), 'PNG')
示例6: make_thumbnail
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def make_thumbnail(image, percent=None, fit=None, dim=None, dest_file=None,
pad=False, pad_fill="black"):
"""Resizes an image to fit within given bounds, or scales it down to a percent
of its original size. Returns a PIL Image.
"""
if not isinstance(image, Image.Image):
image = Image.open(image, "r")
w, h = image.size
if not percent:
if fit:
fit_w, fit_h = fit
percent = min(fit_w/w, fit_h/h)
if percent >= 1:
# The original is smaller than the desired dimensions.
resized = image
else:
resized = image.resize(
(int(w*percent), int(h*percent)),
Image.LANCZOS)
return pad(image, fit_w, fit_h, pad_fill or "black") if pad else image
示例7: load_and_save
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def load_and_save(save_file, size=None):
data = []
languages = get_subdirs(os.path.join(data_dir, 'omniglot'))
for language_num, language in enumerate(languages):
characters = get_subdirs(language)
characters.sort()
for character_num, character in enumerate(characters):
character_images = []
instances = os.listdir(character)
instances.sort()
for instance in instances:
im = Image.open(os.path.join(character, instance))
if size:
im = im.resize((size, size), resample=Image.LANCZOS)
image = np.array(im.getdata()).astype('float32').reshape(size, size) / 255.
image = 1.0 - image # invert the data as Omniglot is black on white
character_images.append((image, character_num, language_num))
data.append(character_images)
np.save(save_file, np.array(data))
示例8: load_pngs
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def load_pngs(input_dir, data, size):
items = get_subdirs(input_dir)
for item_index, item in enumerate(items):
print(item)
item_images = []
instances = []
# There are 36 generated orientations for each item
for i in range(0, 36):
instances.append("{0:02d}.png".format(i))
for instance_index, instance in enumerate(instances):
im = Image.open(os.path.join(item, instance))
if size:
im = im.resize((size, size), resample=Image.LANCZOS)
image = np.array(im.getdata()).astype('float32').reshape(size, size) / 255. # grayscale image
item_images.append((image, item_index, instance_index))
data.append(item_images)
return data
示例9: test_passthrough
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def test_passthrough(self):
# When no resize is required
im = hopper()
for size, box in [
((40, 50), (0, 0, 40, 50)),
((40, 50), (0, 10, 40, 60)),
((40, 50), (10, 0, 50, 50)),
((40, 50), (10, 20, 50, 70)),
]:
try:
res = im.resize(size, Image.LANCZOS, box)
self.assertEqual(res.size, size)
self.assert_image_equal(res, im.crop(box))
except AssertionError:
print('>>>', size, box)
raise
示例10: top_bottom_cut
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def top_bottom_cut(input_image):
"""
Cut off randomly part
of the top and bottom of
input_image and reshape it to the original dimensions
:param input_image: image
:type input_image: numpy.ndarray
:return: cropped image
:rtype: numpy.ndarray
"""
height = input_image.shape[0]
width = input_image.shape[1]
input_dtype = input_image.dtype
top = int(np.random.uniform(.325, .425) * height)
bottom = int(np.random.uniform(.075, .175) * height)
input_image = input_image[top:-bottom, :]
img = Image.fromarray(input_image)
img = img.resize((width, height), Image.LANCZOS)
cut_image = np.array(img).astype(input_dtype)
return cut_image
示例11: preprocess_image
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def preprocess_image(image):
return image
# def preprocess_image(image):
# """Preprocessing the Image for tesseract."""
# # Upscale an image x2
# image = image.resize((4*image.size[0], 4*image.size[1]), resample=Image.LANCZOS)
# image = np.array(image)
# image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# kernel = np.ones((1, 1), np.uint8)
# image = cv2.dilate(image, kernel, iterations=1)
# image = cv2.erode(image, kernel, iterations=1)
# image = cv2.GaussianBlur(image, (5, 5), 0)
#
# return image
示例12: __init__
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def __init__(self, *commands, prefixes=None, strict=False):
"""Answers with image containing stylish quote."""
if not commands:
commands = ("цитата",)
super().__init__(*commands, prefixes=prefixes, strict=strict)
self.q = Image.open(self.get_path("q.png")).resize((40, 40), Image.LANCZOS)
self.qf = self.q.copy().transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.FLIP_TOP_BOTTOM)
self.f = ImageFont.truetype(self.get_path("font.ttf"), 24)
self.fs = ImageFont.truetype(self.get_path("font.ttf"), 16)
self.fss = ImageFont.truetype(self.get_path("font.ttf"), 15)
example = self.command_example()
self.description = [f"Генератор цитат",
f"{example} [титул] - перешлите сообщение и укажите титул (по желанию) и "
"получите цитату!"]
示例13: downsize_img
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def downsize_img(img: ImageType, max_w: int, max_h: int) -> Tuple[ImageType, bool]:
""" Reduce the size of an image to the indicated maximum dimensions
This function takes a PIL.Image object and integer values for the maximum
allowed width and height (a zero value means no maximum constraint),
calculates the size that meets those constraints and resizes the image. The
resize is done in place, changing the original object. Returns a boolean
indicating if the image was changed.
"""
w, h = img.size
# Assume 0 as current size
if not max_w:
max_w = w
if not max_h:
max_h = h
if (max_w, max_h) == (w, h): # If no changes, do nothing
return img, False
img.thumbnail((max_w, max_h), resample=Image.LANCZOS)
return img, True
示例14: multi_setup_pillow
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def multi_setup_pillow(monitors, save_path, wp_setter_func=None):
images = list(map(Image.open, [m.wallpaper for m in monitors]))
resolutions = [(m.width * m.scaling, m.height * m.scaling) for m in monitors]
offsets = [(m.offset_x, m.offset_y) for m in monitors]
# DEBUG
# for m in monitors:
# print(m)
final_image_width = max([m.offset_x + m.width * m.scaling for m in monitors])
final_image_height = max([m.offset_y + m.height * m.scaling for m in monitors])
# DEBUG
# print('Final Size: {} x {}'.format(final_image_width, final_image_height))
n_images = []
for i, r in zip(images, resolutions):
n_images.append(fit(i, r, method=Image.LANCZOS))
final_image = Image.new('RGB', (final_image_width, final_image_height))
for i, o in zip(n_images, offsets):
final_image.paste(i, o)
final_image.save(save_path)
示例15: _fixed_resize
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import LANCZOS [as 別名]
def _fixed_resize(img, size, interpolation=Image.LANCZOS):
"""
Doesn't do the annoying runtime scale dimension switching the default
pytorch transform does.
Args:
img (PIL.Image): image to resize
size (tuple): Tuple (height, width)
"""
w, h = img.size
oh, ow = size
if oh == 0:
oh = int(h * ow/w)
elif ow == 0:
ow = int(w * oh/h)
img = img.resize((ow, oh), interpolation)
return img