Python PIL.ImageEnhance 模块,Color() 实例源码

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

项目:inyourface    作者:yacomink    | 项目源码 | 文件源码
def maskFace(self, frame_image, face):

        img1 = cv2.imread(self.__class__.mask_path, cv2.IMREAD_UNCHANGED);
        elements = cv2.imread(self.__class__.mask_elements_path, cv2.IMREAD_UNCHANGED);

        h, status = cv2.findHomography(self.average_points, np.array(self.getFacePoints(face)))
        mask = self.getTransPIL(cv2.warpPerspective(img1, h, (frame_image.width,frame_image.height)))
        mask_elements = self.getTransPIL(cv2.warpPerspective(elements, h, (frame_image.width,frame_image.height)))

        enhancer = ImageEnhance.Color(frame_image)
        enhanced = enhancer.enhance(0.1)
        enhancer = ImageEnhance.Brightness(enhanced)
        enhanced = enhancer.enhance(1.2)
        enhancer = ImageEnhance.Contrast(enhanced)
        enhanced = enhancer.enhance(1.2)

        frame_image.paste(enhanced, (0,0), mask)
        frame_image.paste(mask_elements, (0,0), mask_elements)
项目:nuts-ml    作者:maet3608    | 项目源码 | 文件源码
def change_color(image, color=1.0):
    """
    Change color of image.

    >>> image = np.eye(3, dtype='uint8') * 255
    >>> change_color(image, 0.5)
    array([[255,   0,   0],
           [  0, 255,   0],
           [  0,   0, 255]], dtype=uint8)

    See
    http://pillow.readthedocs.io/en/3.1.x/reference/ImageEnhance.html#PIL.ImageEnhance.Color

    :param numpy array image: Numpy array with range [0,255] and dtype 'uint8'.
    :param float color: Color [0, 1]
    :return: Image with changed color
    :rtype: numpy array with range [0,255] and dtype 'uint8'
    """
    return enhance(image, ie.Color, color)
项目:dogbot    作者:slice    | 项目源码 | 文件源码
def wacky(self, ctx, image_source: converters.Image = None):
        """Applies wacky effects to your avatar."""
        image_source = image_source or ctx.message.author.avatar_url_as(format='png')

        await ctx.channel.trigger_typing()
        avatar_bio = await get_bytesio(self.bot.session, image_source)

        # Attempt to load the avatar.
        try:
            avatar_im = Image.open(avatar_bio)
        except:
            await ctx.send('I couldn\'t load that person\'s avatar.')
            logger.exception('Wacky avatar processing error:')
            avatar_bio.close()
            return

        enhancer = ImageEnhance.Color(avatar_im)
        avatar_im = await self.bot.loop.run_in_executor(None, enhancer.enhance, 50)

        await export_image(ctx, avatar_im, 'result.png')

        avatar_bio.close()
        avatar_im.close()
项目:wx-fancy-pic    作者:Lavande    | 项目源码 | 文件源码
def lomoize (image,darkness,saturation):

    (width,height) = image.size

    max = width
    if height > width:
        max = height

    mask = Image.open("./lomolive/lomomask.jpg").resize((max,max))

    left = round((max - width) / 2)
    upper = round((max - height) / 2)

    mask = mask.crop((left,upper,left+width,upper + height))

#   mask = Image.open('mask_l.png')

    darker = ImageEnhance.Brightness(image).enhance(darkness)   
    saturated = ImageEnhance.Color(image).enhance(saturation)
    lomoized = Image.composite(saturated,darker,mask)

    return lomoized
项目:deep-prior    作者:moberweger    | 项目源码 | 文件源码
def getJitteredImgs(self, img, num, maxRot=(-5.0, 5.0), maxTranslate=(-2.0, 2.0), maxScale=(-0.1, 0.1), augmentColor=False):
        """ 
        Take img and jitter it
        :return: a list of all jittered images
        """

        cx = img.size[0] / 2
        cy = img.size[1] / 2

        tMats = self.getJitteredParams(center=(cx, cy), num=num, maxRot=maxRot, maxTranslate=maxTranslate,
                                       maxScale=maxScale)
        imgs = []
        for i in range(len(tMats)):
            t = tMats[i]
            imgT = self.transformImg(img, t)

            if augmentColor:
                # jitter colors
                color = ImageEnhance.Color(imgT)
                imgT = color.enhance(self.rng.uniform(0.7, 1))

                # jitter contrast
                contr = ImageEnhance.Contrast(imgT)
                imgT = contr.enhance(self.rng.uniform(0.7, 1))

                # jitter brightness
                bright = ImageEnhance.Brightness(imgT)
                imgT = bright.enhance(self.rng.uniform(0.7, 1))

                # add noise
                im = numpy.asarray(imgT).astype('int') + numpy.rint(self.rng.normal(0, 4, numpy.asarray(imgT).shape)).astype('int')
                im = numpy.clip(im, 0, 255).astype('uint8')
                imgT = Image.fromarray(im)

            # add image
            imgs.append(imgT)

        return imgs, tMats
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def do_color(self):
        """usage: color <image:pic1>

        Enhance color in the top image.
        """
        from PIL import ImageEnhance
        factor = float(self.do_pop())
        image = self.do_pop()
        enhancer = ImageEnhance.Color(image)
        self.push(enhancer.enhance(factor))
项目:PyLabyrinthe    作者:yoann-darche    | 项目源码 | 文件源码
def doMonsterStatus(self, MonsterList):
        """
        Fonction assurant l'affichage de l'état des monstres
        """

        # Si pas de changement exit direct
        if not(MonsterList.hasUpdate): return None

        print("CtxGfx::doMonsterStatus >> Doing")
        MonsterList.hasUpdate = False

        w = self.nx*self.rx

        nb_total = len(MonsterList.ActiveMonsterList) + len(MonsterList.InActiveMonsterList)

        w_monster = nb_total * (self.rx + 2)

        x_offset = (self.nx*self.rx - w_monster) // 2

        # Création du tableau des monstres

        monsterBoard = Image.new('RGBA',(w_monster, 40), (0,0,255,0)) 

        k = 0
        for m in MonsterList.ActiveMonsterList:            
            monsterBoard.paste(m.Sprite,(k*(self.rx + 2), 4))
            k = k+1

        for m in MonsterList.InActiveMonsterList:
            tmpSprite = ImageEnhance.Color(m.Sprite)
            monsterBoard.paste(tmpSprite.enhance(0.0),(k*(self.rx + 2), 4))
            k = k+1

        self.cInfo.delete(self.tkMonsterBoard) 
        self.cInfo.delete(self.tkMonsterBoardId) 
        self.tkMonsterBoard = ImageTk.PhotoImage(image=monsterBoard,  master=self.cInfo)
        self.tkMonsterBoardId = self.cInfo.create_image(x_offset, 0, anchor=Tk.NW, image=self.tkMonsterBoard, state= Tk.NORMAL)
项目:mlAlgorithms    作者:gu-yan    | 项目源码 | 文件源码
def color_enhance(self, factor, new_path=None, is_show=False):
        if self.img is None:
            img = Image.open(self.path)
        else:
            img = self.img
        img = ImageEnhance.Color(img).enhance(factor)
        if new_path is not None:
            img.save(new_path)
        if is_show:
            img.show(title='color')
        return img
项目:MLUtil    作者:WarBean    | 项目源码 | 文件源码
def color(func_config):
    def f(image_config):
        factor = misc.uniform_sample_from_interval(func_config.min_factor, func_config.max_factor)
        image_config.image = ImageEnhance.Color(image_config.image).enhance(factor)
    return f
项目:img_augmentation    作者:huvers    | 项目源码 | 文件源码
def make_clr_chg(file_name, path_dir):
    file_path = path_dir + '/' + file_name
    img = Image.open('%s' % file_path)
    ImageEnhance.Color(img).enhance(0.8).save(path_dir + '/' + '%02s_clr'
                                              % file_name.translate(None, '.png') + '.png', "PNG")
    return
项目:PyGram    作者:achillesrasquinha    | 项目源码 | 文件源码
def nss(image):
    size     = image.size
    nss      = Image.new('RGBA', size, (243, 106, 188, 77))
    enhancer = ImageEnhance.Contrast(nss)
    enhancer.enhance(1.1)
    enhancer = ImageEnhance.Brightness(nss)
    enhancer.enhance(1.1)
    enhancer = ImageEnhance.Color(nss)
    enhancer.enhance(1.3)

    copy     = image.copy()

    copy.paste(nss, (0, 0), nss)

    return copy
项目:PyGram    作者:achillesrasquinha    | 项目源码 | 文件源码
def clarendon(image):
    size      = image.size
    clarendon = Image.new('RGBA', size, (127, 187, 227, 51))
    enhancer  = ImageEnhance.Contrast(clarendon)
    enhancer.enhance(1.20)
    enhancer  = ImageEnhance.Color(clarendon)
    enhancer.enhance(1.35)

    copy      = image.copy()

    copy.paste(clarendon, (0, 0), clarendon)

    return copy
项目:road_simulator    作者:vinzeebreak    | 项目源码 | 文件源码
def call(self, img):

        if img is None: raise ValueError('img is None')

        im_n = img.copy()

        r = random()
        contrast_low, contrast_high = 0, self.contrast
        brightness_low, brightness_high = contrast_high, contrast_high + self.brightness
        sharpness_low, sharpness_high = brightness_high, brightness_high + self.sharpness
        color_low, color_high = sharpness_high, sharpness_high + self.color

        if contrast_low <= r < contrast_high:
            factor_contrast = randint(5, 10)/10
            enhancer = ImageEnhance.Contrast(im_n)
            im_n = enhancer.enhance(factor_contrast)
        elif brightness_low <= r < brightness_high:
            factor_brightness = randint(5, 15)/10
            enhancer = ImageEnhance.Brightness(im_n)
            im_n = enhancer.enhance(factor_brightness)
        elif sharpness_low <= r < sharpness_high:
            factor_sharpen = randint(0, 20)/10
            enhancer = ImageEnhance.Sharpness(im_n)
            im_n = enhancer.enhance(factor_sharpen)
        elif color_low <= r < color_high:
            factor_color = randint(0, 20)/10
            enhancer = ImageEnhance.Color(im_n)
            im_n = enhancer.enhance(factor_color)
        else:
            pass

        return im_n
项目:Bahavior-Based-Robot    作者:Marcgrippa    | 项目源码 | 文件源码
def scale_colors(self,image=False,degree=0.5):
        image = image if image else self.image
        return Imager(image=ImageEnhance.Color(image).enhance(degree))
项目:lantern-detection    作者:gongxijun    | 项目源码 | 文件源码
def randomColor(image):
        """
        ?????????
        :param image: PIL???image
        :return: ????????image
        """
        random_factor = np.random.randint(0, 31) / 10.  # ????
        color_image = ImageEnhance.Color(image).enhance(random_factor)  # ????????
        random_factor = np.random.randint(10, 21) / 10.  # ????
        brightness_image = ImageEnhance.Brightness(color_image).enhance(random_factor)  # ???????
        random_factor = np.random.randint(10, 21) / 10.  # ???1?
        contrast_image = ImageEnhance.Contrast(brightness_image).enhance(random_factor)  # ???????
        random_factor = np.random.randint(0, 31) / 10.  # ????
        return ImageEnhance.Sharpness(contrast_image).enhance(random_factor)  # ??????
项目:TWEleReceipt    作者:hsucw    | 项目源码 | 文件源码
def tesseract(self, img):
        # keep the data
        fileName = "tmp_"+int(time.time()+random.randint(1,99999)).__str__()+".jpeg"
        while os.path.exists( fileName ):
            fileName = "tmp_"+int(time.time()+random.randint(1,99999)).__str__()+".jpeg"
        self.tmp_file = fileName
        with open(self.tmp_file, "w") as oFd:
            oFd.write(img)

        # resolve noise
        try:
            im = Image.open(self.tmp_file)
            enhancer = ImageEnhance.Color(im)
            im = enhancer.enhance(0.0)
            enhancer = ImageEnhance.Contrast(im)
            im = enhancer.enhance(3.0)
            enhancer = ImageEnhance.Brightness(im)
            im = enhancer.enhance(10.0)
            enhancer = ImageEnhance.Contrast(im)
            im = enhancer.enhance(20.0)
            enhancer = ImageEnhance.Sharpness(im)
            im = enhancer.enhance(0.0)
            im.save(self.tmp_file)
        except Exception as e:
            pass
        else:
            pass
        # use tesseract

        imgCode = os.popen("tesseract -l eng -psm 8 {} stdout 2>/dev/null"\
                .format(self.tmp_file)).readline()[0:-1]
        log.debug("Guess Ratio:{}/{}={}%".format(self.guess_hit+1, self.guess_total, \
                ((self.guess_hit+1)*100/(self.guess_total))))

        os.remove( self.tmp_file )


        return imgCode
项目:tanda    作者:HazyResearch    | 项目源码 | 文件源码
def TF_enhance_color(x, p=1.0):
    assert len(x.shape) == 3
    h, w, nc = x.shape

    enhancer = ImageEnhance.Color(np_to_pil(x))
    return pil_to_np(enhancer.enhance(p))