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


Python ImageFilter.SHARPEN屬性代碼示例

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


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

示例1: imfilter

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [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

示例2: test_sanity

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [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

示例3: imfilter

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [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

示例4: post

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [as 別名]
def post(self, request, *args, **kwargs):
        with PyTessBaseAPI() as api:
            with Image.open(request.FILES['image']) as image:
                sharpened_image = image.filter(ImageFilter.SHARPEN)
                api.SetImage(sharpened_image)
                utf8_text = api.GetUTF8Text()

        return JsonResponse({'utf8_text': utf8_text}) 
開發者ID:abarto,項目名稱:ocr-with-django,代碼行數:10,代碼來源:views.py

示例5: FilterImage

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [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

示例6: ocr

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [as 別名]
def ocr(
         x_start :int,
         y_start :int,
         x_end :int,
         y_end :int,
         debug :bool =False,
         bmp :image =None,
         cropb :bool =False,
         filter :bool =True,
         binf :int =0,
         sliced :bool =False
     ) -> str:
        """Perform an OCR of the supplied area, returns a string of the result.
        
        Keyword arguments
        debug  -- Saves an image of what is sent to the OCR (default False)
        bmp    -- A bitmap from the get_bitmap() function, use this if you're
                  performing multiple different OCR-readings in succession from
                  the same page. This is to avoid to needlessly get the same
                  bitmap multiple times. If a bitmap is not passed, the function
                  will get the bitmap itself. (default None)
        cropb  -- Whether the bmp provided should be cropped.
        filter -- Whether to filter the image for better OCR.
        binf   -- Threshold value for binarizing filter. Zero means no filtering.
        sliced -- Whether the image has ben sliced so there's very little blank
                  space. Gets better readings from small values for some reason.
        """
        x_start += Window.x
        x_end   += Window.x
        y_start += Window.y
        y_end   += Window.y

        if bmp is None:
            bmp = Inputs.get_cropped_bitmap(x_start, y_start, x_end, y_end)
        
        elif cropb:
            # Bitmaps are created with a 8px border
            bmp = bmp.crop((x_start + 8, y_start + 8, x_end + 8, y_end + 8))
        
        if binf > 0: # Binarizing Filter
            fn = lambda x : 255 if x > binf else 0
            bmp = bmp.convert('L') # To Monochrome
            bmp = bmp.point(fn, mode='1')
            if debug: bmp.save("debug_ocr_whiten.png")
        
        if filter: # Resizing and sharpening
            *_, right, lower = bmp.getbbox()
            bmp = bmp.resize((right * 4, lower * 4), image.BICUBIC)  # Resize image
            bmp = bmp.filter(ImageFilter.SHARPEN)
            if debug: bmp.save("debug_ocr_filter.png")
            
        if sliced: s = pytesseract.image_to_string(bmp, config='--psm 6')
        else:      s = pytesseract.image_to_string(bmp, config='--psm 4')
        
        return s 
開發者ID:kujan,項目名稱:NGU-scripts,代碼行數:57,代碼來源:inputs.py

示例7: imfilter

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

    This function is only available if Python Imaging Library (PIL) is installed.

    .. warning::

        This function uses `bytescale` under the hood to rescale images to use
        the full (0, 255) range if ``mode`` is one of ``None, 'L', 'P', 'l'``.
        It will also cast data for 2-D images to ``uint32`` for ``mode=None``
        (which is the default).

    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:ryfeus,項目名稱:lambda-packs,代碼行數:52,代碼來源:pilutil.py

示例8: binarization_image

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import SHARPEN [as 別名]
def binarization_image(image, invert_image=True, threshold=127):
    """
    銳化圖片,二值化圖像,之後顏色反轉,以增加ocr識別精確度
    原因是tesseract在識別黑底白字和白底黑字會有不同表現:
    黑底白字有問題,而白底黑字可以識別
    Arknights中截取的圖片大多為黑底白字,所以轉變為白底黑字
    :param invert_image: 是否顏色反轉圖片,絕大部分如理智判斷,需要反轉圖片,但有部分不需要
    :param image: 輸入圖片
    :param threshold: 臨界灰度值,原來是200,現在改為175,有人report問題issue#24; 現在改回PIL默認的127,鬼知道為啥之前的就不行
    :return: 返回二值化圖片,但暫時沒有用,tesseract的調用方式導致必須有個圖片路徑,
             變量的方式不知道怎麽弄過去,百度OCR倒是可以,但沒弄
    """
    # 百度api有的時候需要二值化,有時二值化反而會造成負麵影響
    # if save_backup:
    #     # 這裏給二值化前的圖片留個底,確認二值化異常的原因
    #     try:
    #         copy(image, image + ".DebugBackup.png")
    #     except IOError as e:
    #         print("Unable to copy file. {}".format(e))
    #     except:
    #         print("Unexpected error:", sys.exc_info())
    # picture = Image.open(image)
    # 銳化圖片
    sharpen = image.filter(ImageFilter.SHARPEN)
    # 灰度化
    final = sharpen.convert('L')
    # 顏色反轉
    if invert_image:
        final = ImageOps.invert(final)
    # 二值化,這裏其實可以直接使用inverted_image.convert(1)來完成,但為了保障閾值可控,這裏“手動”一下
    # table = []
    # for i in range(256):
    #     if i < threshold:
    #         table.append(0)
    #     else:
    #         table.append(1)
    # 這裏該用似乎是更快速的方式
    lut = lambda x: 1 if x > threshold else 0
    bim = final.point(lut, '1')
    # bim.save(image)
    return bim

# def image_threshold(image, threshold=127):
#     """
#     threshold filter on L channel
#     :param threshold: negative value means inverted output
#     """
#     if threshold < 0:
#         lut = lambda x: 0 if x > -threshold else 1
#     else:
#         lut = lambda x: 1 if x > threshold else 0
#     return image.convert('L').point(lut, '1') 
開發者ID:ninthDevilHAUNSTER,項目名稱:ArknightsAutoHelper,代碼行數:54,代碼來源:Binarization.py


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