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


Python Image.LANCZOS属性代码示例

本文整理汇总了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 
开发者ID:Bartzi,项目名称:stn-ocr,代码行数:18,代码来源:create_svhn_dataset.py

示例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 
开发者ID:cgwire,项目名称:zou,代码行数:23,代码来源:thumbnail.py

示例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 
开发者ID:weclaw1,项目名称:inbac,代码行数:21,代码来源:controller.py

示例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') 
开发者ID:ildoonet,项目名称:kaggle-human-protein-atlas-image-classification,代码行数:20,代码来源:download_hpa.py

示例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 
开发者ID:codeforboston,项目名称:cornerwise,代码行数:26,代码来源:images.py

示例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)) 
开发者ID:Gordonjo,项目名称:versa,代码行数:24,代码来源:save_omniglot_data.py

示例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 
开发者ID:Gordonjo,项目名称:versa,代码行数:22,代码来源:save_shapenet_data.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:19,代码来源:test_image_resample.py

示例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 
开发者ID:felipessalvatore,项目名称:self_driving_pi_car,代码行数:23,代码来源:image_manipulation.py

示例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 
开发者ID:Nukesor,项目名称:sticker-finder,代码行数:18,代码来源:image.py

示例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} [титул] - перешлите сообщение и укажите титул (по желанию) и "
                             "получите цитату!"] 
开发者ID:ekonda,项目名称:sketal,代码行数:21,代码来源:quote.py

示例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 
开发者ID:victordomingos,项目名称:optimize-images,代码行数:23,代码来源:img_aux_processing.py

示例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) 
开发者ID:GabMus,项目名称:HydraPaper,代码行数:24,代码来源:wallpaper_merger.py

示例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 
开发者ID:mittagessen,项目名称:kraken,代码行数:19,代码来源:dataset.py


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