Python PIL.ImageFilter.MinFilter() Examples
The following are 8
code examples of PIL.ImageFilter.MinFilter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
PIL.ImageFilter
, or try the search function
.
Example #1
Source File: test_image_filter.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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")
Example #2
Source File: test_image_filter.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #3
Source File: test_image_filters.py From pliers with BSD 3-Clause "New" or "Revised" License | 6 votes |
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])
Example #4
Source File: helpers.py From OdooQuant with GNU General Public License v3.0 | 6 votes |
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(' ', '')
Example #5
Source File: captcha.py From easytrader with MIT License | 6 votes |
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)
Example #6
Source File: gfTrader.py From vxTrader with MIT License | 5 votes |
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)
Example #7
Source File: mobi.py From kmanga with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: Downloader.py From m2em with MIT License | 4 votes |
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)