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


Python ImageFilter.MinFilter方法代碼示例

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


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

示例1: test_rankfilter

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

        def rankfilter(mode):
            im = Image.new(mode, (3, 3), None)
            im.putdata(list(range(9)))
            # image is:
            #   0 1 2
            #   3 4 5
            #   6 7 8
            minimum = im.filter(ImageFilter.MinFilter).getpixel((1, 1))
            med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1))
            maximum = im.filter(ImageFilter.MaxFilter).getpixel((1, 1))
            return minimum, med, maximum

        self.assertEqual(rankfilter("1"), (0, 4, 8))
        self.assertEqual(rankfilter("L"), (0, 4, 8))
        self.assertRaises(ValueError, rankfilter, "P")
        self.assertEqual(rankfilter("RGB"), ((0, 0, 0), (4, 0, 0), (8, 0, 0)))
        self.assertEqual(rankfilter("I"), (0, 4, 8))
        self.assertEqual(rankfilter("F"), (0.0, 4.0, 8.0)) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:22,代碼來源:test_image_filter.py

示例2: test_pillow_image_filter_filter

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MinFilter [as 別名]
def test_pillow_image_filter_filter():
    stim = ImageStim(join(IMAGE_DIR, 'thai_people.jpg'))
    with pytest.raises(ValueError):
        filt = PillowImageFilter()
    filt = PillowImageFilter('BLUR')
    blurred = filt.transform(stim)
    assert blurred is not None

    from PIL import ImageFilter
    filt2 = PillowImageFilter(ImageFilter.FIND_EDGES)
    edges = filt2.transform(stim)
    assert np.array_equal(edges.data[0, 0], [134, 85, 45])

    filt3 = PillowImageFilter(ImageFilter.MinFilter(3))
    min_img = filt3.transform(stim)
    assert np.array_equal(min_img.data[0, 0], [122, 74, 36])

    filt4 = PillowImageFilter('MinFilter')
    min_img = filt4.transform(stim)
    assert np.array_equal(min_img.data[0, 0], [122, 74, 36])

    filt5 = PillowImageFilter(ImageFilter.MaxFilter, size=3)
    med_img = filt5.transform(stim)
    assert np.array_equal(med_img.data[0, 0], [136, 86, 49]) 
開發者ID:tyarkoni,項目名稱:pliers,代碼行數:26,代碼來源:test_image_filters.py

示例3: detect_gf_result

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MinFilter [as 別名]
def detect_gf_result(image_path):
    from PIL import ImageFilter, Image
    import pytesseract
    img = Image.open(image_path)
    for x in range(img.width):
        for y in range(img.height):
            if img.getpixel((x, y)) < (100, 100, 100):
                img.putpixel((x, y), (256, 256, 256))
    gray = img.convert('L')
    two = gray.point(lambda x: 0 if 68 < x < 90 else 256)
    min_res = two.filter(ImageFilter.MinFilter)
    med_res = min_res.filter(ImageFilter.MedianFilter)
    for _ in range(2):
        med_res = med_res.filter(ImageFilter.MedianFilter)
    res = pytesseract.image_to_string(med_res, config='-psm 6')
    return res.replace(' ', '') 
開發者ID:haogefeifei,項目名稱:OdooQuant,代碼行數:18,代碼來源:helpers.py

示例4: detect_gf_result

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MinFilter [as 別名]
def detect_gf_result(image_path):
    from PIL import ImageFilter, Image

    img = Image.open(image_path)
    if hasattr(img, "width"):
        width, height = img.width, img.height
    else:
        width, height = img.size
    for x in range(width):
        for y in range(height):
            if img.getpixel((x, y)) < (100, 100, 100):
                img.putpixel((x, y), (256, 256, 256))
    gray = img.convert("L")
    two = gray.point(lambda p: 0 if 68 < p < 90 else 256)
    min_res = two.filter(ImageFilter.MinFilter)
    med_res = min_res.filter(ImageFilter.MedianFilter)
    for _ in range(2):
        med_res = med_res.filter(ImageFilter.MedianFilter)
    return invoke_tesseract_to_recognize(med_res) 
開發者ID:shidenggui,項目名稱:easytrader,代碼行數:21,代碼來源:captcha.py

示例5: test_sanity

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

示例6: vcode

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

        # 獲取校驗碼
        r = self._session.get('https://trade.gf.com.cn/yzm.jpgx')
        r.raise_for_status()

        # 通過內存保存圖片,進行識別
        img_buffer = BytesIO(r.content)
        img = Image.open(img_buffer)
        if hasattr(img, "width"):
            width, height = img.width, img.height
        else:
            width, height = img.size
        for x in range(width):
            for y in range(height):
                if img.getpixel((x, y)) < (100, 100, 100):
                    img.putpixel((x, y), (256, 256, 256))

        gray = img.convert('L')
        two = gray.point(lambda x: 0 if 68 < x < 90 else 256)
        min_res = two.filter(ImageFilter.MinFilter)
        med_res = min_res.filter(ImageFilter.MedianFilter)
        for _ in range(1):
            med_res = med_res.filter(ImageFilter.MedianFilter)

        # 通過tesseract-ocr的工具進行校驗碼識別
        vcode = pytesseract.image_to_string(med_res)
        img.close()
        img_buffer.close()

        vcode = vcode.replace(' ', '')
        if self.code_rule.findall(vcode) != []:
            logger.debug('vcode is: %s' % vcode)
            return vcode
        else:
            raise VerifyCodeError('verify code error: %s' % vcode) 
開發者ID:vex1023,項目名稱:vxTrader,代碼行數:38,代碼來源:gfTrader.py

示例7: filter_footer

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MinFilter [as 別名]
def filter_footer(self, img):
        """Filter to remove the hight quality footer for an image."""
        # Some sites like MangaFox add an extra footer in the original
        # image.  This footer remove importan space in the Kindle, and
        # we need to remove it.
        #
        # The algorithm use as a leverage the normal noise present in
        # an scanned image, that is higher than the one in the footer.
        # This means that this filter will only work in medium quality
        # scanners, but possibly not in high quality ones.
        #
        # The process is like this:
        #
        #   1.- Binarize the image, moving the noise at the same level
        #       that the real information.
        #
        #   2.- Use a MinFilter of size 3 to a big mass of pixels that
        #       containg high frequency data.  That usually means
        #       pixels surrounded with blanks.
        #
        #   3.- Do a Gaussian filter to lower more the high frequency
        #       data, moving the mass close arround the pixel.  This
        #       will lower more the pixels surrounded with gaps.
        #
        #   4.- Discard the pixels with low mass.
        #
        _img = ImageOps.invert(img.convert(mode='L'))
        _img = _img.point(lambda x: x and 255)
        _img = _img.filter(ImageFilter.MinFilter(size=3))
        _img = _img.filter(ImageFilter.GaussianBlur(radius=5))
        _img = _img.point(lambda x: (x >= 48) and x)
        # If the image is white, we do not have bbox
        return img.crop(_img.getbbox()) if _img.getbbox() else img 
開發者ID:aplanas,項目名稱:kmanga,代碼行數:35,代碼來源:mobi.py

示例8: downloader

# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MinFilter [as 別名]
def downloader(self, url, counter, parser):
        """Method that downloads files"""

        # Check if we have the Download folder
        helper.createFolder(self.downloadfolder)

        imagepath = self.downloadfolder + "/" + str("{0:0=3d}".format(counter)) + ".png"
        tempdl = self.downloadfolder + "/" + str("{0:0=3d}".format(counter)) + ".tmp"

        # Download the image!
        f = open(tempdl, 'wb')
        f.write(requests.get(parser(url), headers={'referer': url}).content)
        f.close()

        # convert img to png
        imgtest = Image.open(tempdl)
        if imgtest.format != 'PNG':
            logging.debug("Image %s is not a PNG... convertig.", tempdl)
            imgtest.save(tempdl, "PNG")
        else:
            imgtest.close()

        # If everything is alright, write image to final name
        os.rename(tempdl, imagepath)


        # Cleanse image, remove footer
        #
        #   I have borrowed this code from the kmanga project.
        #   https://github.com/aplanas/kmanga/blob/master/mobi/mobi.py#L416
        #   Thanks a lot to Alberto Planas for coming up with it!
        #
        if self.origin == "mangafox.me" or self.origin == "mangafox.la" or self.origin == "fanfox.net":
            logging.debug("Cleaning Mangafox Footer")
            img = Image.open(imagepath)
            _img = ImageOps.invert(img.convert(mode='L'))
            _img = _img.point(lambda x: x and 255)
            _img = _img.filter(ImageFilter.MinFilter(size=3))
            _img = _img.filter(ImageFilter.GaussianBlur(radius=5))
            _img = _img.point(lambda x: (x >= 48) and x)

            cleaned = img.crop(_img.getbbox()) if _img.getbbox() else img
            cleaned.save(imagepath) 
開發者ID:schemen,項目名稱:m2em,代碼行數:45,代碼來源:Downloader.py


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