Python PIL.ImageOps 模块,equalize() 实例源码

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

项目:cuicuilco    作者:AlbertoEsc    | 项目源码 | 文件源码
def final_sampling_and_contrast_enhance(im_contrasted, out_size, x0, x1, y0, y1, contrast_enhance):
    subimage_coordinates = (x0, y0, x1, y1)
    if contrast_enhance == "PostEqualizeHistogram":
        # Resize, then equalize
        im_out = im_contrasted.transform(out_size, Image.EXTENT, subimage_coordinates,
                                         interpolation_format_sampling)  # W interpolation_format       format_nearest
        im_out = ImageOps.equalize(im_out)
    elif contrast_enhance == "SmartEqualizeHistogram":
        # Crop, then equalize, then resize
        out_size_crop = (x1 - x0, y1 - y0)
        im_out = im_contrasted.transform(out_size_crop, Image.EXTENT, subimage_coordinates,
                                         interpolation_format_sampling)  # W interpolation_format       format_nearest
        im_out = ImageOps.equalize(im_out)
        crop_coordinates = (0, 0, x1 - x0, y1 - y0)
        im_out = im_out.transform(out_size, Image.EXTENT, crop_coordinates,
                                  interpolation_format_sampling)  # W interpolation_format       format_nearest
    else:
        im_out = im_contrasted.transform(out_size, Image.EXTENT, subimage_coordinates, interpolation_format_sampling)
    return im_out
项目:Learn-to-identify-similar-images    作者:MashiMaroLjc    | 项目源码 | 文件源码
def classfiy_aHash(image1,image2,size=(8,8),exact=25):
    ''' 'image1' and 'image2' is a Image Object.
    You can build it by 'Image.open(path)'.
    'Size' is parameter what the image will resize to it and then image will be compared by the algorithm.
    It's 8 * 8 when it default.  
    'exact' is parameter for limiting the Hamming code between 'image1' and 'image2',it's 25 when it default.
    The result become strict when the exact become less. 
    This function return the true when the 'image1'  and 'image2' are similar. 
    '''
    image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
    image1 = ImageOps.equalize(image1)
    code1 = getCode(image1, size)
    image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
    image2 = ImageOps.equalize(image2)
    code2 = getCode(image2, size)

    assert len(code1) == len(code2),"error"

    return compCode(code1, code2)<=exact
项目:hacker-scripts    作者:restran    | 项目源码 | 文件源码
def classify_ahash(cls, image1, image2, size=(8, 8), exact=25):
        """ 'image1' and 'image2' is a Image Object.
        You can build it by 'Image.open(path)'.
        'Size' is parameter what the image will resize to it and then image will be compared by the algorithm.
        It's 8 * 8 when it default.
        'exact' is parameter for limiting the Hamming code between 'image1' and 'image2',it's 25 when it default.
        The result become strict when the exact become less.
        This function return the true when the 'image1'  and 'image2' are similar.
        """
        image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
        image1 = ImageOps.equalize(image1)
        code1 = cls.get_code(image1, size)
        image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
        image2 = ImageOps.equalize(image2)
        code2 = cls.get_code(image2, size)

        assert len(code1) == len(code2), "error"

        return cls.compare_code(code1, code2)
项目:enet-keras    作者:PavlosMelissinos    | 项目源码 | 文件源码
def normalize(img):
    if isinstance(img, np.ndarray):
        processed_img = ImageOps.equalize(PILImage.fromarray(img, mode='RGB'))
    else:
        processed_img = ImageOps.equalize(img)
    return processed_img


# masks
项目:inception-face-shape-classifier    作者:adonistio    | 项目源码 | 文件源码
def equalize_img(imdir,outdir):    
    im = Image.open(imdir)
    out_filename = outdir
    ImageOps.equalize(im).save(out_filename, 'JPEG', quality = 100)
项目:Learn-to-identify-similar-images    作者:MashiMaroLjc    | 项目源码 | 文件源码
def classify_DCT(image1,image2,size=(32,32),part_size=(8,8)):
    """ 'image1' and 'image2' is a Image Object.
    You can build it by 'Image.open(path)'.
    'Size' is parameter what the image will resize to it and then image will be compared by the pHash.
    It's 32 * 32 when it default. 
    'part_size' is a size of a part of the matrix after Discrete Cosine Transform,which need to next steps.
    It's 8 * 8 when it default. 

    The function will return the hamming code,less is correct. 
    """
    assert size[0]==size[1],"size error"
    assert part_size[0]==part_size[1],"part_size error"

    image1 = image1.resize(size).convert('L').filter(ImageFilter.BLUR)
    image1 = ImageOps.equalize(image1)
    matrix = get_matrix(image1)
    DCT_matrix = DCT(matrix)
    List = sub_matrix_to_list(DCT_matrix, part_size)
    middle = get_middle(List)
    code1 = get_code(List, middle)


    image2 = image2.resize(size).convert('L').filter(ImageFilter.BLUR)
    image2 = ImageOps.equalize(image2)
    matrix = get_matrix(image2)
    DCT_matrix = DCT(matrix)
    List = sub_matrix_to_list(DCT_matrix, part_size)
    middle = get_middle(List)
    code2 = get_code(List, middle)



    return comp_code(code1, code2)