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


Python ImageFilter.BLUR屬性代碼示例

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


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

示例1: make_photo

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def make_photo(self, dir_):
        """生成驗證碼

        :param dir_: 存放驗證碼照片的文件夾
        """
        from PIL import Image  # 安裝pillow: pip install pillow
        from PIL import ImageFont
        from PIL import ImageDraw
        from PIL import ImageFilter
        image = Image.new('RGB', (self.width, self.height), (255, 255, 255))
        font = ImageFont.truetype('arial.ttf', 36)

        draw = ImageDraw.Draw(image)
        for w in range(self.width):
            for h in range(self.height):
                draw.point((w, h), fill=self.color1())
        for index, t in enumerate(self.flag):
            draw.text(((self.width - 10) // self.number * index + 10, 10), t, font=font, fill=self.color2())
        image = image.filter(ImageFilter.BLUR)
        image.save(dir_ + sep + ''.join(self.flag) + '.jpg', 'jpeg')
        return image 
開發者ID:jtyoui,項目名稱:Jtyoui,代碼行數:23,代碼來源:captcha.py

示例2: _add_dropshadow

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def _add_dropshadow(self, image, offset=(4,4), background=0x000, shadow=0x0F0, border=3, iterations=5):
        totalWidth = image.size[0] + abs(offset[0]) + 2*border
        totalHeight = image.size[1] + abs(offset[1]) + 2*border
        back = Image.new(image.mode, (totalWidth, totalHeight), background)

        # Place the shadow, taking into account the offset from the image
        shadowLeft = border + max(offset[0], 0)
        shadowTop = border + max(offset[1], 0)
        back.paste(shadow, [shadowLeft, shadowTop, shadowLeft + image.size[0], shadowTop + image.size[1]])

        n = 0
        while n < iterations:
            back = back.filter(ImageFilter.BLUR)
            n += 1

        # Paste the input image onto the shadow backdrop
        imageLeft = border - min(offset[0], 0)
        imageTop = border - min(offset[1], 0)
        back.paste(image, (imageLeft, imageTop))
        return back 
開發者ID:AznStevy,項目名稱:Maybe-Useful-Cogs,代碼行數:22,代碼來源:leveler.py

示例3: classify_ahash

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def classify_ahash(cls, image1, image2, size=(8, 8), exact=25):
        """ 'image1' and 'image2' is a Image Object.
        You can build it by 'Image.open(path)'.
        'Size' is parameter what the image will resize to it and then image will be compared by the algorithm.
        It's 8 * 8 when it default.
        'exact' is parameter for limiting the Hamming code between 'image1' and 'image2',it's 25 when it default.
        The result become strict when the exact become less.
        This function return the true when the 'image1'  and 'image2' are similar.
        """
        image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
        image1 = ImageOps.equalize(image1)
        code1 = cls.get_code(image1, size)
        image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
        image2 = ImageOps.equalize(image2)
        code2 = cls.get_code(image2, size)

        assert len(code1) == len(code2), "error"

        return cls.compare_code(code1, code2) 
開發者ID:restran,項目名稱:hacker-scripts,代碼行數:21,代碼來源:similar_image.py

示例4: LoadAndBinarizeImage

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def LoadAndBinarizeImage(path):
  orig_im = Image.open(path)
  w, h = orig_im.size
  im = orig_im.crop((80, 80, w - 80, h - 80))
  w, h = im.size
  im = im.resize((w / 5, h / 5), Image.ANTIALIAS)
  blur_im = im.filter(ImageFilter.BLUR)

  I = np.asarray(blur_im).copy()

  brown = np.array([178.1655574, 137.2695507, 90.26289517])
  brown[0] = np.median(I[:,:,0])
  brown[1] = np.median(I[:,:,1])
  brown[2] = np.median(I[:,:,2])

  # I[100:200, 100:200] = brown
  # ShowBinaryArray(I)

  # TODO(danvk): does removing the np.sqrt have an effect on perfomance?
  return (np.sqrt(((I - brown) ** 2).sum(2)/3) >= 20) 
開發者ID:danvk,項目名稱:oldnyc,代碼行數:22,代碼來源:find_pictures.py

示例5: pre_ocr_processing

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def pre_ocr_processing(im):
    im = im.convert("RGB")
    width, height = im.size

    white = im.filter(ImageFilter.BLUR).filter(ImageFilter.MaxFilter(23))
    grey = im.convert('L')
    impix = im.load()
    whitepix = white.load()
    greypix = grey.load()

    for y in range(height):
        for x in range(width):
            greypix[x,y] = min(255, max(255 + impix[x,y][0] - whitepix[x,y][0],
                                        255 + impix[x,y][1] - whitepix[x,y][1],
                                        255 + impix[x,y][2] - whitepix[x,y][2]))

    new_im = grey.copy()
    binarize(new_im, 150)
    return new_im 
開發者ID:andelf,項目名稱:fuck12306,代碼行數:21,代碼來源:fuck12306.py

示例6: random_blur

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def random_blur(image, prob=.1):
    """
    Random add normal blur to image

    # Arguments
        image: origin image for blur
            PIL Image object containing image data
        prob: probability for blur,
            scalar to control the blur probability.

    # Returns
        image: adjusted PIL Image object.
    """
    blur = rand() < prob
    if blur:
        image = image.filter(ImageFilter.BLUR)

    return image 
開發者ID:david8862,項目名稱:keras-YOLOv3-model-set,代碼行數:20,代碼來源:data_utils.py

示例7: imfilter

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def imfilter(arr,ftype):
    """
    Simple filtering of an image.

    Parameters
    ----------
    arr : ndarray
        The array of Image in which the filter is to be applied.
    ftype : str
        The filter that has to be applied. Legal values are:
        'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
        'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'.

    Returns
    -------
    imfilter : ndarray
        The array with filter applied.

    Raises
    ------
    ValueError
        *Unknown filter type.*  If the filter you are trying
        to apply is unsupported.

    """
    _tdict = {'blur':ImageFilter.BLUR,
              'contour':ImageFilter.CONTOUR,
              'detail':ImageFilter.DETAIL,
              'edge_enhance':ImageFilter.EDGE_ENHANCE,
              'edge_enhance_more':ImageFilter.EDGE_ENHANCE_MORE,
              'emboss':ImageFilter.EMBOSS,
              'find_edges':ImageFilter.FIND_EDGES,
              'smooth':ImageFilter.SMOOTH,
              'smooth_more':ImageFilter.SMOOTH_MORE,
              'sharpen':ImageFilter.SHARPEN
              }

    im = toimage(arr)
    if ftype not in _tdict:
        raise ValueError("Unknown filter type.")
    return fromimage(im.filter(_tdict[ftype])) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:43,代碼來源:pilutil.py

示例8: test_sanity

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def test_sanity(self):

        def filter(filter):
            for mode in ["L", "RGB", "CMYK"]:
                im = hopper(mode)
                out = im.filter(filter)
                self.assertEqual(out.mode, im.mode)
                self.assertEqual(out.size, im.size)

        filter(ImageFilter.BLUR)
        filter(ImageFilter.CONTOUR)
        filter(ImageFilter.DETAIL)
        filter(ImageFilter.EDGE_ENHANCE)
        filter(ImageFilter.EDGE_ENHANCE_MORE)
        filter(ImageFilter.EMBOSS)
        filter(ImageFilter.FIND_EDGES)
        filter(ImageFilter.SMOOTH)
        filter(ImageFilter.SMOOTH_MORE)
        filter(ImageFilter.SHARPEN)
        filter(ImageFilter.MaxFilter)
        filter(ImageFilter.MedianFilter)
        filter(ImageFilter.MinFilter)
        filter(ImageFilter.ModeFilter)
        filter(ImageFilter.GaussianBlur)
        filter(ImageFilter.GaussianBlur(5))
        filter(ImageFilter.BoxBlur(5))
        filter(ImageFilter.UnsharpMask)
        filter(ImageFilter.UnsharpMask(10))

        self.assertRaises(TypeError, filter, "hello") 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:32,代碼來源:test_image_filter.py

示例9: blur_image

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def blur_image(
        self, extension: str = "png", gaussian: bool = False, radius: int = 2
    ):
        """Blur an image
        
        Args:
            extension (str, optional): File extension of loaded image. Defaults to png
            gaussian (bool, optional): If Gaussian blur is to be applied. Defaults to False.
            radius (int, optional): Radius for Gaussian blur. Defaults to 2.
        
        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> c = Chepy("logo.png").load_file().blur_image("png")
            >>> >>> c.write('/path/to/file.png', as_binary=True)

            To apply Gaussian blur, use:

            >>> c = Chepy("logo.png").load_file()
            >>> c.blur_image(extension="png", gaussian=True, radius=4)
            >>> >>> c.write('/path/to/file.png', as_binary=True)
        """
        image = Image.open(self._load_as_file())
        fh = io.BytesIO()
        if gaussian:
            blurred = image.filter(ImageFilter.GaussianBlur(radius=radius))
        else:
            blurred = image.filter(ImageFilter.BLUR)
        blurred.save(fh, extension)
        self.state = fh.getvalue()
        return self 
開發者ID:securisec,項目名稱:chepy,代碼行數:34,代碼來源:multimedia.py

示例10: __init__

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def __init__(self, image_name, only_size_needed=True):
        self.imageName = image_name
        self.original = Image.open(image_name)

        if not only_size_needed:
            self.resized = self.original.resize((50, 50))
            # self.resized = self.resized.filter(ImageFilter.BLUR)

            # load image data
            self.img_data = self.resized.load() 
開發者ID:varietywalls,項目名稱:variety,代碼行數:12,代碼來源:DominantColors.py

示例11: imfilter

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def imfilter(arr, ftype):
    """
    Simple filtering of an image.

    Parameters
    ----------
    arr : ndarray
        The array of Image in which the filter is to be applied.
    ftype : str
        The filter that has to be applied. Legal values are:
        'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more',
        'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'.

    Returns
    -------
    imfilter : ndarray
        The array with filter applied.

    Raises
    ------
    ValueError
        *Unknown filter type.*  If the filter you are trying
        to apply is unsupported.

    """
    _tdict = {'blur': ImageFilter.BLUR,
              'contour': ImageFilter.CONTOUR,
              'detail': ImageFilter.DETAIL,
              'edge_enhance': ImageFilter.EDGE_ENHANCE,
              'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE,
              'emboss': ImageFilter.EMBOSS,
              'find_edges': ImageFilter.FIND_EDGES,
              'smooth': ImageFilter.SMOOTH,
              'smooth_more': ImageFilter.SMOOTH_MORE,
              'sharpen': ImageFilter.SHARPEN
              }

    im = toimage(arr)
    if ftype not in _tdict:
        raise ValueError("Unknown filter type.")
    return fromimage(im.filter(_tdict[ftype])) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:43,代碼來源:pilutil.py

示例12: convert

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def convert(fname, crop_size):
    img = Image.open(fname)

    blurred = img.filter(ImageFilter.BLUR)
    ba = np.array(blurred)
    h, w, _ = ba.shape

    if w > 1.2 * h:
        left_max = ba[:, : w // 32, :].max(axis=(0, 1)).astype(int)
        right_max = ba[:, - w // 32:, :].max(axis=(0, 1)).astype(int)
        max_bg = np.maximum(left_max, right_max)

        foreground = (ba > max_bg + 10).astype(np.uint8)
        bbox = Image.fromarray(foreground).getbbox()

        if bbox is None:
            print('bbox none for {} (???)'.format(fname))
        else:
            left, upper, right, lower = bbox
            # if we selected less than 80% of the original 
            # height, just crop the square
            if right - left < 0.8 * h or lower - upper < 0.8 * h:
                print('bbox too small for {}'.format(fname))
                bbox = None
    else:
        bbox = None

    if bbox is None:
        bbox = square_bbox(img)

    cropped = img.crop(bbox)
    resized = cropped.resize([crop_size, crop_size])
    return resized 
開發者ID:sveitser,項目名稱:kaggle_diabetic,代碼行數:35,代碼來源:convert.py

示例13: FilterImage

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def FilterImage(image, filter_name):
    """Applies an arbitrary filtering to a PIL image. Note that this does not
    work for two-byte images.

    Input:
        image               a PIL image as 8-bit RGB or grayscale.
        filter_name         name of the filter to be applied. Choices are
                            "NONE", "BLUR", "CONTOUR", "DETAIL" ,"EDGE_ENHANCE",
                            "EDGE_ENHANCE_MORE", "EMBOSS", "FIND_EDGES",
                            "SMOOTH", "SMOOTH_MORE", "SHARPEN", "MEDIAN_3",
                            "MEDIAN_5", "MEDIAN_7", "MINIMUM_3", "MINIMUM_5",
                            "MINIMUM_7" ,"MAXIMUM_3", "MAXIMUM_5", and
                            "MAXIMUM_7".

    Return:                 a pointer to the filtered image.
    """

    if type(image) == list:
        raise ValueError("filtering of 2-byte images is not supported")

    # Look up filter method
    if filter:
        filter_method = FILTER_DICT[filter_name.upper()]
    else:
        filter_method = None

    # Apply filter if necessary
    if filter_method: image = image.filter(filter_method)

    return image

################################################################################
# Re-size a PIL image
################################################################################ 
開發者ID:SETI,項目名稱:pds-tools,代碼行數:36,代碼來源:picmaker.py

示例14: get_captcha

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def get_captcha(width,height,num_of_str,gray_value=255):
    image = Image.new('RGB', (width, height), (255, 255, 255))

    # 創建Font對象:
    font = ImageFont.truetype('ヒラギノ角ゴシック W8.ttc', 31) # '/Library/Fonts/Bodoni 72.ttc'

    # 創建Draw對象:
    draw = ImageDraw.Draw(image)

    # 填充每個像素:
    for x in range(width):
        for y in range(height):
            # draw.point((x, y), fill=rndColor())
            draw.point((x, y), fill=(255,255,255))

    # 輸出文字:
    char_list = [rndChar() for i in range(num_of_str)]

    for t in range(num_of_str):
        # rndColor2()
        draw.text((height * t, 1), char_list[t], font=font, fill=(0,0,0))

    # 模糊:
    # image = image.filter(ImageFilter.BLUR)
    # image.save('train_imgs/1.png', 'jpeg');
    return char_list,image 
開發者ID:aboutmydreams,項目名稱:pycapt,代碼行數:28,代碼來源:make_capt.py

示例15: mk_captcha

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import BLUR [as 別名]
def mk_captcha(my_str_list,width,height,num_of_str,font=30,gray_value=255,font_family='ヒラギノ角ゴシック W8.ttc'):
    image = Image.new('RGB', (width, height), (255, 255, 255))

    # 創建Font對象:
    font = ImageFont.truetype(font_family, font) # '/Library/Fonts/Bodoni 72.ttc'  'ヒラギノ角ゴシック W8.ttc'

    # 創建Draw對象:
    draw = ImageDraw.Draw(image)

    # 填充每個像素:
    for x in range(width):
        for y in range(height):
            # draw.point((x, y), fill=rndColor())
            draw.point((x, y), fill=(255,255,255))

    # 輸出文字:
    char_list = my_random_str(my_str_list,num_of_str)

    for t in range(num_of_str):
        # rndColor2()
        draw.text((height * t, 1), char_list[t], font=font, fill=(0,0,0))

    # 模糊:
    # image = image.filter(ImageFilter.BLUR)
    # image.save('train_imgs/1.png', 'jpeg');
    return char_list,image


### 測試
# a,b = mk_captcha(['A','B','1','2','3','4'],160,40,4)
# print(a)
# b.show() 
開發者ID:aboutmydreams,項目名稱:pycapt,代碼行數:34,代碼來源:my_any_img.py


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