Python PIL.ImageFilter 模块,MedianFilter() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用PIL.ImageFilter.MedianFilter()

项目:OdooQuant    作者:haogefeifei    | 项目源码 | 文件源码
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(' ', '')
项目:easytrader    作者:yuzhucu    | 项目源码 | 文件源码
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)
项目:GraduationDesign    作者:pstreeplus    | 项目源码 | 文件源码
def gray(image):
        """
        :return: self.images

        ?????
        """

        image = image.convert('RGB')
        image = image.filter(ImageFilter.MedianFilter())
        r, g, b = image.split()
        x, y = image.size
        for j in xrange(x):
            for k in xrange(y):
                pixelr = r.getpixel((j, k))
                pixelg = g.getpixel((j, k))
                pixelb = b.getpixel((j, k))
                pixel = int(0.3 * pixelr + 0.59 * pixelg + 0.11 * pixelb)
                r.putpixel((j, k), pixel)
        image = r
        image = image.filter(ImageFilter.MedianFilter())
        return image
项目:gougo    作者:amaozhao    | 项目源码 | 文件源码
def autocrop(im, autocrop=False, **kwargs):
    """
    Remove any unnecessary whitespace from the edges of the source image.

    This processor should be listed before :func:`scale_and_crop` so the
    whitespace is removed from the source image before it is resized.

    autocrop
        Activates the autocrop method for this image.

    """
    if autocrop:
        # If transparent, flatten.
        if utils.is_transparent(im) and False:
            no_alpha = Image.new('L', im.size, (255))
            no_alpha.paste(im, mask=im.split()[-1])
        else:
            no_alpha = im.convert('L')
        # Convert to black and white image.
        bw = no_alpha.convert('L')
        # bw = bw.filter(ImageFilter.MedianFilter)
        # White background.
        bg = Image.new('L', im.size, 255)
        bbox = ImageChops.difference(bw, bg).getbbox()
        if bbox:
            im = im.crop(bbox)
    return im
项目:vxTrader    作者:vex1023    | 项目源码 | 文件源码
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)
项目:GraduationDesign    作者:pstreeplus    | 项目源码 | 文件源码
def binaryzation(image):
        """
        :return: ret_images

        ?????
        """
        x, y = image.size
        for j in xrange(x):
            for k in xrange(y):
                pixel = 0 if image.getpixel((j, k)) > 100 else 255
                image.putpixel((j, k), pixel)
        image = image.filter(ImageFilter.MedianFilter())
        return image
项目:Image-Processing-and-Steganogrphy    作者:motkeg    | 项目源码 | 文件源码
def ImgMax(img):
    img=img.filter(ImageFilter.SMOOTH)
    img=img.filter(ImageFilter.MedianFilter(5))
    img.show()
项目:VerifyCode    作者:Guardiant    | 项目源码 | 文件源码
def ModifyImg(self,img_name):
        global val_img
        val_img+=1
        if val_img <= 1:
            print('??????????----------')
            if os.path.isdir(Modif):
                pass
            else:
                mkdir = os.makedirs(Modif)
                print('????????????????????----------')
                print('???????????????????->'+Modif)
        else:
            pass

        img = Image.open(img_name)
        img = img.filter(ImageFilter.MedianFilter())
        enhancer = ImageEnhance.Contrast(img)
        img = enhancer.enhance(2)
        img = img.convert('1')

        width, height = img.size
        data = []
        for i in range(height):
            tmp=[]
            for j in range(width):
                if(img.getpixel((j,i)) == 255 ):
                    tmp.append(1)
                else:
                    tmp.append(0)
            data.append(tmp)

        img2 = Image.new("P",img.size, 255)
        for y in range(height):
            for a in range(len(data[y])):

                o = y+1
                t = y+2
                #s = y+3
                z = a+1
                x = a+2
                try:
                    if data[o][a] == 0 and data[t][a] == 0 and data[y][z] == 0  and data[y][x] == 0:#and data[s][a] == 0 
                        img2.putpixel((a,y),1)
                        img2.save(Modif+str(val_img)+'.png')


                except:
                    pass
        img2_path = Modif+str(val_img)+'.png'

        image = Image.open(img2_path)  
        image = image.convert("L")  
        self.clearNoise(image,53,4,8)  
        image.save(img2_path)  
        image.show()
        self.ImgCutting(img2_path)