Python PIL.ImageFilter 模块,EDGE_ENHANCE_MORE 实例源码

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

项目:Verification-code-crack    作者:weixianglin    | 项目源码 | 文件源码
def remove_line(giffile,savepath):
    (img,pixdata) = open_img(giffile)
    for x in range(img.size[0]):
        for y in range(img.size[1]):
            if pixdata[x,y][0]<8 or pixdata[x,y][1]<6 or pixdata[x,y][2]<8 or (pixdata[x,y][0]+pixdata[x,y][1]+pixdata[x,y][2])<=30:
                if y==0:
                    pixdata[x, y] = (255, 255, 255)
                if y>0:
                    if pixdata[x, y-1][0] > 120 or pixdata[x, y-1][1] > 136 or pixdata[x, y-1][2] > 120:
                        pixdata[x,y] = (255,255,255)

    #?????
    for y in range(img.size[1]):  # ???????????R=95?G=95?B=95
        for x in range(img.size[0]):
            if pixdata[x, y][0] < 160 and pixdata[x, y][1] < 160 and pixdata[x, y][2] < 160:
                pixdata[x, y] = (0, 0, 0)
            else:
                pixdata[x, y] = (255, 255, 255)
    img.filter(ImageFilter.EDGE_ENHANCE_MORE)#????(????)
    img.resize(((img.size[0])*2,(img.size[1])*2),Image.BILINEAR)#Image.BILINEAR??????????????
    img.save(savepath)
项目:Verification-code-crack    作者:weixianglin    | 项目源码 | 文件源码
def remove_line(giffile, savepath):
    (img, pixdata) = open_img(giffile)
    for x in range(img.size[0]):    #x??
        for y in range(img.size[1]):    #y??
            if pixdata[x, y][0] < 8 or pixdata[x, y][1] < 6 or pixdata[x, y][2] < 8 or (
                    pixdata[x, y][0] + pixdata[x, y][1] + pixdata[x, y][2]) <= 30:  #??????
                if y == 0:
                    pixdata[x, y] = (255, 255, 255)
                if y > 0:
                    if pixdata[x, y - 1][0] > 120 or pixdata[x, y - 1][1] > 136 or pixdata[x, y - 1][2] > 120:
                        pixdata[x, y] = (255, 255, 255) #?

    # ?????
    for y in range(img.size[1]):  # ???????????R=95?G=95?B=95
        for x in range(img.size[0]):
            if pixdata[x, y][0] < 160 and pixdata[x, y][1] < 160 and pixdata[x, y][2] < 160:
                pixdata[x, y] = (0, 0, 0)
            else:
                pixdata[x, y] = (255, 255, 255)
    img.filter(ImageFilter.EDGE_ENHANCE_MORE)  #?????????????????????????????????????
    img.resize(((img.size[0]) * 2, (img.size[1]) * 2), Image.BILINEAR)  # Image.BILINEAR??????????????#?
    img.save(savepath+'captcha_removeline.gif')

#?????????????????????dot_num?
项目:captcha_project    作者:zhanghe06    | 项目源码 | 文件源码
def get(self):
        if self.draw_lines:
            self._create_lines()
        if self.draw_points:
            self._create_points()
        code_str = self._create_code_str()

        # ??????
        params = [1 - float(random.randint(1, 2)) / 100,
                  0,
                  0,
                  0,
                  1 - float(random.randint(1, 10)) / 100,
                  float(random.randint(1, 2)) / 500,
                  0.001,
                  float(random.randint(1, 2)) / 500
                  ]
        img = self.img.transform(self.size, Image.PERSPECTIVE, params)  # ????

        img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)  # ?????????????

        return img, code_str
项目:flask-maple    作者:honmaple    | 项目源码 | 文件源码
def create_validate_code(self,
                             size=(120, 30),
                             chars=init_chars,
                             img_type="GIF",
                             mode="RGB",
                             bg_color=(255, 255, 255),
                             fg_color=(0, 0, 255),
                             font_size=18,
                             font_type=fontType,
                             length=4,
                             draw_lines=True,
                             n_line=(1, 2),
                             draw_points=True,
                             point_chance=2):

        width, height = size
        img = Image.new(mode, size, bg_color)
        draw = ImageDraw.Draw(img)
        if draw_lines:
            self.create_lines(draw, n_line, width, height)
        if draw_points:
            self.create_points(draw, point_chance, width, height)
            strs = self.create_strs(draw, chars, length, font_type, font_size,
                                    width, height, fg_color)

        params = [1 - float(randint(1, 2)) / 100, 0, 0, 0,
                  1 - float(randint(1, 10)) / 100, float(randint(1, 2)) / 500,
                  0.001, float(randint(1, 2)) / 500]
        img = img.transform(size, Image.PERSPECTIVE, params)

        img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)

        return img, strs
项目:antitools    作者:bufubaoni    | 项目源码 | 文件源码
def code_img(code, size):
    r = Random()
    code = code
    len_code = len(code)

    font = ImageFont.truetype("Essence_Sans.ttf", size)

    font_width, font_height = font.getsize(code)
    font_width += size / 2
    print font_width, font_height
    img = Image.new("RGBA", (font_width, font_height), (255,) * 4)

    draw = ImageDraw.ImageDraw(img)

    draw.text((size/10, -size/10), code, font=font, fill=(0, 0, 0))

    params = [1,
              0,
              0,
              0,
              1 - float(r.randint(1, 10)) / 100,
              0,
              0.001,
              float(r.randint(1, 2)) / 500
              ]
    print params
    img = img.transform((font_width, font_height), Image.PERSPECTIVE, params)
    img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)

    img.save("test.jpg")
项目:utils    作者:Ctrlsman    | 项目源码 | 文件源码
def rd_check_code(width=120, height=30, char_length=5, font_file='kumo.ttf', font_size=28):
    code = []
    img = Image.new(mode='RGB', size=(width, height), color=(255, 255, 255))
    draw = ImageDraw.Draw(img, mode='RGB')

    def rndChar():
        """
        ??????   
        :return:
        """
        return chr(random.randint(65, 90))

    def rndColor():
        """
        ??????
        :return:
        """
        return (random.randint(0, 255), random.randint(10, 255), random.randint(64, 255))

    # ???
    font = ImageFont.truetype(font_file, font_size)
    for i in range(char_length):
        char = rndChar()
        code.append(char)
        h = random.randint(0, 4)
        draw.text([i * width / char_length, h], char, font=font, fill=rndColor())

    # ????
    for i in range(40):
        draw.point([random.randint(0, width), random.randint(0, height)], fill=rndColor())

    # ?????
    for i in range(40):
        draw.point([random.randint(0, width), random.randint(0, height)], fill=rndColor())
        x = random.randint(0, width)
        y = random.randint(0, height)
        draw.arc((x, y, x + 4, y + 4), 0, 90, fill=rndColor())

    # ????
    for i in range(5):
        x1 = random.randint(0, width)
        y1 = random.randint(0, height)
        x2 = random.randint(0, width)
        y2 = random.randint(0, height)

        draw.line((x1, y1, x2, y2), fill=rndColor())

    img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
    return img, ''.join(code)
项目:music_recommend    作者:YeEmrick    | 项目源码 | 文件源码
def create_validate_code(size=(120, 30),
                         chars=init_chars,
                         img_type="GIF",
                         mode="RGB",
                         bg_color=(245, 245, 245),
                         fg_color=color_random,
                         font_size=24,
                         font_type=fontType,
                         length=4,
                         draw_lines=True,
                         n_line=(1, 2),
                         draw_points=True,
                         point_chance=2):
    '''
    @todo: ???????
    @param size: ?????????????????(120, 30)
    @param chars: ?????????????
    @param img_type: ???????????GIF?????GIF?JPEG?TIFF?PNG
    @param mode: ????????RGB
    @param bg_color: ??????????
    @param fg_color: ?????????????????#0000FF
    @param font_size: ???????
    @param font_type: ????????? ae_AlArabiya.ttf
    @param length: ???????
    @param draw_lines: ??????
    @param n_lines: ?????????????????(1, 2)???draw_lines?True???
    @param draw_points: ??????
    @param point_chance: ?????????????[0, 100]
    @return: [0]: PIL Image??
    @return: [1]: ??????????
    '''

    width, height = size  # ?? ?
    img = Image.new(mode, size, bg_color)  # ????
    draw = ImageDraw.Draw(img)  # ????
    if draw_lines:
        create_lines(draw, n_line, width, height)
    if draw_points:
        create_points(draw, point_chance, width, height)
    strs = create_strs(draw, chars, length, font_type, font_size, width, height, fg_color())

    # ??????
    params = [1 - float(random.randint(1, 2)) / 100,
              0,
              0,
              0,
              1 - float(random.randint(1, 10)) / 100,
              float(random.randint(1, 2)) / 500,
              0.001,
              float(random.randint(1, 2)) / 500
              ]
    img = img.transform(size, Image.PERSPECTIVE, params)  # ????

    img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)  # ?????????????

    return img, strs