本文整理匯總了Python中PIL.ImageFilter.MedianFilter方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageFilter.MedianFilter方法的具體用法?Python ImageFilter.MedianFilter怎麽用?Python ImageFilter.MedianFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.ImageFilter
的用法示例。
在下文中一共展示了ImageFilter.MedianFilter方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: median_filter
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [as 別名]
def median_filter(self, size):
""" Calculates a multidimensional median filter
Parameters
----------
size: int
The kernel size in pixels.
Returns
----------
The median filtered image.
"""
from PIL import Image, ImageFilter
image = Image.fromarray(self.Image)
image = image.filter(ImageFilter.MedianFilter(size=size))
return np.array(image)
示例2: test_rankfilter
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [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))
示例3: detect_gf_result
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [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(' ', '')
示例4: detect_gf_result
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [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)
示例5: test_median_filter
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [as 別名]
def test_median_filter(self):
#Check median filter
from PIL import Image, ImageFilter
dt = DataTransforms(self.d)
filtered = dt.median_filter(size=3)
image = Image.fromarray(self.d)
image = image.filter(ImageFilter.MedianFilter(size=3))
check_filtered = np.array(image)
assert np.allclose(check_filtered, filtered)
示例6: test_sanity
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [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")
示例7: vcode
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [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)
示例8: _blow_up_image
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [as 別名]
def _blow_up_image():
try:
img = Image.open(args.image)
except FileNotFoundError:
print(colored("[!] I couldn't find a file by that name. Fake you!",
'red'))
return False
except OSError:
print(colored("[!] {} is not an image file!".format(args.image),
'red'))
return False
basewidth = 2500
img = Image.open(args.image)
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
# Resize happens here
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
# Thanks Stack Overflow <3 : https://stackoverflow.com/a/37750605/5486120
img = img.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2)
# Return the sexy image object
return img
示例9: blur_image
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [as 別名]
def blur_image(pil_img,mode,r):
if mode == "g":
kernel = ImageFilter.GaussianBlur(radius=r)
elif mode == "m":
kernel = ImageFilter.MedianFilter(size=r)
else:
raise ValueError("{} not support".format(mode))
return pil_img.filter(kernel)
示例10: medianfilter
# 需要導入模塊: from PIL import ImageFilter [as 別名]
# 或者: from PIL.ImageFilter import MedianFilter [as 別名]
def medianfilter(self, image, size=3):
return image.filter(ImageFilter.MedianFilter(size=size))