當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageEnhance.Brightness方法代碼示例

本文整理匯總了Python中PIL.ImageEnhance.Brightness方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageEnhance.Brightness方法的具體用法?Python ImageEnhance.Brightness怎麽用?Python ImageEnhance.Brightness使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PIL.ImageEnhance的用法示例。


在下文中一共展示了ImageEnhance.Brightness方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: adjust_brightness

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def adjust_brightness(img, brightness_factor):
    """Adjust brightness of an Image.

    Args:
        img (PIL Image): PIL Image to be adjusted.
        brightness_factor (float):  How much to adjust the brightness. Can be
            any non negative number. 0 gives a black image, 1 gives the
            original image while 2 increases the brightness by a factor of 2.

    Returns:
        PIL Image: Brightness adjusted image.
    """
    if not _is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

    enhancer = ImageEnhance.Brightness(img)
    img = enhancer.enhance(brightness_factor)
    return img 
開發者ID:miraiaroha,項目名稱:ACAN,代碼行數:20,代碼來源:transforms.py

示例2: ela

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def ela(filename, output_path):
    print "****ELA is in BETA****"
    if magic.from_file(filename, mime=True) == "image/jpeg":
        quality_level = 85
        tmp_img = os.path.join(output_path,os.path.basename(filename)+".tmp.jpg")
        ela = os.path.join(output_path,os.path.basename(filename)+".ela.jpg")
        image = Image.open(filename)
        image.save(tmp_img, 'JPEG', quality=quality_level)
        tmp_img_file = Image.open(tmp_img)
        ela_image = ImageChops.difference(image, tmp_img_file)
        extrema = ela_image.getextrema()
        max_diff = max([ex[1] for ex in extrema])
        scale = 255.0/max_diff
        ela_image = ImageEnhance.Brightness(ela_image).enhance(scale)
        ela_image.save(ela)
        os.remove(tmp_img)
    else:
        print "ELA works only with JPEG"


#Modified version of a gist by: https://github.com/erans 
開發者ID:redaelli,項目名稱:imago-forensics,代碼行數:23,代碼來源:extractor.py

示例3: apply_brightness_shift

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def apply_brightness_shift(x, brightness):
    """Performs a brightness shift.

    # Arguments
        x: Input tensor. Must be 3D.
        brightness: Float. The new brightness value.
        channel_axis: Index of axis for channels in the input tensor.

    # Returns
        Numpy image tensor.

    # Raises
        ValueError if `brightness_range` isn't a tuple.
    """
    if ImageEnhance is None:
        raise ImportError('Using brightness shifts requires PIL. '
                          'Install PIL or Pillow.')
    x = array_to_img(x)
    x = imgenhancer_Brightness = ImageEnhance.Brightness(x)
    x = imgenhancer_Brightness.enhance(brightness)
    x = img_to_array(x)
    return x 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:24,代碼來源:image.py

示例4: resize_and_bitmap

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def resize_and_bitmap(self, fname, size, enhance_color=False):
        """Take filename of an image and resize and center crop it to size."""
        try:
            pil = resize_to_fill(Image.open(fname), size, quality="fast")
        except UnidentifiedImageError:
            msg = ("Opening image '%s' failed with PIL.UnidentifiedImageError."
                   "It could be corrupted or is of foreign type.") % fname
            sp_logging.G_LOGGER.info(msg)
            # show_message_dialog(msg)
            black_bmp = wx.Bitmap.FromRGBA(size[0], size[1], red=0, green=0, blue=0, alpha=255)
            if enhance_color:
                return (black_bmp, black_bmp)
            return black_bmp
        img = wx.Image(pil.size[0], pil.size[1])
        img.SetData(pil.convert("RGB").tobytes())
        if enhance_color:
            converter = ImageEnhance.Color(pil)
            pilenh_bw = converter.enhance(0.25)
            brightns = ImageEnhance.Brightness(pilenh_bw)
            pilenh = brightns.enhance(0.45)
            imgenh = wx.Image(pil.size[0], pil.size[1])
            imgenh.SetData(pilenh.convert("RGB").tobytes())
            return (img.ConvertToBitmap(), imgenh.ConvertToBitmap())
        return img.ConvertToBitmap() 
開發者ID:hhannine,項目名稱:superpaper,代碼行數:26,代碼來源:gui.py

示例5: _fry

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def _fry(img):
		e = ImageEnhance.Sharpness(img)
		img = e.enhance(100)
		e = ImageEnhance.Contrast(img)
		img = e.enhance(100)
		e = ImageEnhance.Brightness(img)
		img = e.enhance(.27)
		r, b, g = img.split()
		e = ImageEnhance.Brightness(r)
		r = e.enhance(4)
		e = ImageEnhance.Brightness(g)
		g = e.enhance(1.75)
		e = ImageEnhance.Brightness(b)
		b = e.enhance(.6)
		img = Image.merge('RGB', (r, g, b))
		e = ImageEnhance.Brightness(img)
		img = e.enhance(1.5)
		temp = BytesIO()
		temp.name = 'deepfried.png'
		img.save(temp)
		temp.seek(0)
		return temp 
開發者ID:Flame442,項目名稱:FlameCogs,代碼行數:24,代碼來源:deepfry.py

示例6: image_brightness

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def image_brightness(self, factor: int, extension: str = "png"):
        """Change image brightness
        
        Args:
            factor (int): Factor to increase the brightness by
            extension (str, optional): File extension of loaded image. Defaults to "png"
        
        Returns:
            Chepy: The Chepy object. 
        """
        image = Image.open(self._load_as_file())
        image = self._force_rgb(image)
        fh = io.BytesIO()
        enhanced = ImageEnhance.Brightness(image).enhance(factor)
        enhanced.save(fh, extension)
        self.state = fh.getvalue()
        return self 
開發者ID:securisec,項目名稱:chepy,代碼行數:19,代碼來源:multimedia.py

示例7: modifyImageBscc

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def modifyImageBscc(imageData, brightness, sharpness, contrast, color):
    """Update with brightness, sharpness, contrast and color."""

    brightnessMod = ImageEnhance.Brightness(imageData)
    imageData = brightnessMod.enhance(brightness)

    sharpnessMod = ImageEnhance.Sharpness(imageData)
    imageData = sharpnessMod.enhance(sharpness)

    contrastMod = ImageEnhance.Contrast(imageData)
    imageData = contrastMod.enhance(contrast)

    colorMod = ImageEnhance.Color(imageData)
    imageData = colorMod.enhance(color)

    return imageData 
開發者ID:BerkeleyLearnVerify,項目名稱:VerifAI,代碼行數:18,代碼來源:generator.py

示例8: lomoize

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
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 
開發者ID:Lavande,項目名稱:wx-fancy-pic,代碼行數:24,代碼來源:lomolive.py

示例9: __getitem__

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def __getitem__(self, index):
        im, xpatch, ypatch, rotation, flip, enhance = np.unravel_index(index, self.shape)

        with Image.open(self.names[im]) as img:
            extractor = PatchExtractor(img=img, patch_size=PATCH_SIZE, stride=self.stride)
            patch = extractor.extract_patch((xpatch, ypatch))

            if rotation != 0:
                patch = patch.rotate(rotation * 90)

            if flip != 0:
                patch = patch.transpose(Image.FLIP_LEFT_RIGHT)

            if enhance != 0:
                factors = np.random.uniform(.5, 1.5, 3)
                patch = ImageEnhance.Color(patch).enhance(factors[0])
                patch = ImageEnhance.Contrast(patch).enhance(factors[1])
                patch = ImageEnhance.Brightness(patch).enhance(factors[2])

            label = self.labels[self.names[im]]
            return transforms.ToTensor()(patch), label 
開發者ID:ImagingLab,項目名稱:ICIAR2018,代碼行數:23,代碼來源:datasets.py

示例10: adjust_brightness

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def adjust_brightness(img, brightness_factor):
    """Adjust brightness of an Image.
    Args:
    img (PIL Image): PIL Image to be adjusted.
    brightness_factor (float):  How much to adjust the brightness. Can be
    any non negative number. 0 gives a black image, 1 gives the
    original image while 2 increases the brightness by a factor of 2.
    Returns:
    PIL Image: Brightness adjusted image.
    """
    if not is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

    enhancer = ImageEnhance.Brightness(img)
    img = enhancer.enhance(brightness_factor)
    return img 
開發者ID:almazan,項目名稱:deep-image-retrieval,代碼行數:18,代碼來源:transforms_tools.py

示例11: random_brightness

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def random_brightness(x, brightness_range):
    """Perform a random brightness shift.

    # Arguments
        x: Input tensor. Must be 3D.
        brightness_range: Tuple of floats; brightness range.
        channel_axis: Index of axis for channels in the input tensor.

    # Returns
        Numpy image tensor.

    # Raises
        ValueError if `brightness_range` isn't a tuple.

    """
    if len(brightness_range) != 2:
        raise ValueError('`brightness_range should be tuple or list of two floats. '
                         'Received arg: ', brightness_range)

    x = array_to_img(x)
    x = imgenhancer_Brightness = ImageEnhance.Brightness(x)
    u = np.random.uniform(brightness_range[0], brightness_range[1])
    x = imgenhancer_Brightness.enhance(u)
    x = img_to_array(x)
    return x 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:27,代碼來源:image.py

示例12: produce

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def produce(txt,img,ver=5,err_crt = qrcode.constants.ERROR_CORRECT_H,bri = 1.0, cont = 1.0,\
        colourful = False, rgba = (0,0,0,255),pixelate = False):
    """Produce QR code

    :txt: QR text
    :img: Image path / Image object
    :ver: QR version
    :err_crt: QR error correct
    :bri: Brightness enhance
    :cont: Contrast enhance
    :colourful: If colourful mode
    :rgba: color to replace black
    :pixelate: pixelate
    :returns: list of produced image

    """
    if type(img) is Image.Image:
        pass
    elif type(img) is str:
        img = Image.open(img)
    else:
        return []
    frames = [produce_impl(txt,frame.copy(),ver,err_crt,bri,cont,colourful,rgba,pixelate) for frame in ImageSequence.Iterator(img)]
    return frames 
開發者ID:chinuno-usami,項目名稱:CuteR,代碼行數:26,代碼來源:CuteR.py

示例13: save_img

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def save_img(fname, image, image_enhance=False):  # 圖像可以增強
    image = Image.fromarray(image)
    if image_enhance:
        # 亮度增強
        enh_bri = ImageEnhance.Brightness(image)
        brightness = 1.2
        image = enh_bri.enhance(brightness)

        # 色度增強
        enh_col = ImageEnhance.Color(image)
        color = 1.2
        image = enh_col.enhance(color)

        # 銳度增強
        enh_sha = ImageEnhance.Sharpness(image)
        sharpness = 1.2
        image = enh_sha.enhance(sharpness)
    imsave(fname, image)
    return 
開發者ID:yuweiming70,項目名稱:Style_Migration_For_Artistic_Font_With_CNN,代碼行數:21,代碼來源:neural_style_transfer.py

示例14: adjust_brightness

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def adjust_brightness(img, brightness_factor):
    """Adjust brightness of an Image.
    Args:
        img (PIL.Image): PIL Image to be adjusted.
        brightness_factor (float):  How much to adjust the brightness. Can be
            any non negative number. 0 gives a black image, 1 gives the
            original image while 2 increases the brightness by a factor of 2.
    Returns:
        PIL.Image: Brightness adjusted image.
    """
    if not _is_pil_image(img):
        raise TypeError('img should be PIL Image. Got {}'.format(type(img)))

    enhancer = ImageEnhance.Brightness(img)
    img = enhancer.enhance(brightness_factor)
    return img 
開發者ID:YuanXue1993,項目名稱:SegAN,代碼行數:18,代碼來源:transform.py

示例15: __init__

# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Brightness [as 別名]
def __init__(self):
        self.policies = [
            ['Invert', 0.1, 7, 'Contrast', 0.2, 6],
            ['Rotate', 0.7, 2, 'TranslateX', 0.3, 9],
            ['Sharpness', 0.8, 1, 'Sharpness', 0.9, 3],
            ['ShearY', 0.5, 8, 'TranslateY', 0.7, 9],
            ['AutoContrast', 0.5, 8, 'Equalize', 0.9, 2],
            ['ShearY', 0.2, 7, 'Posterize', 0.3, 7],
            ['Color', 0.4, 3, 'Brightness', 0.6, 7],
            ['Sharpness', 0.3, 9, 'Brightness', 0.7, 9],
            ['Equalize', 0.6, 5, 'Equalize', 0.5, 1],
            ['Contrast', 0.6, 7, 'Sharpness', 0.6, 5],
            ['Color', 0.7, 7, 'TranslateX', 0.5, 8],
            ['Equalize', 0.3, 7, 'AutoContrast', 0.4, 8],
            ['TranslateY', 0.4, 3, 'Sharpness', 0.2, 6],
            ['Brightness', 0.9, 6, 'Color', 0.2, 8],
            ['Solarize', 0.5, 2, 'Invert', 0, 0.3],
            ['Equalize', 0.2, 0, 'AutoContrast', 0.6, 0],
            ['Equalize', 0.2, 8, 'Equalize', 0.6, 4],
            ['Color', 0.9, 9, 'Equalize', 0.6, 6],
            ['AutoContrast', 0.8, 4, 'Solarize', 0.2, 8],
            ['Brightness', 0.1, 3, 'Color', 0.7, 0],
            ['Solarize', 0.4, 5, 'AutoContrast', 0.9, 3],
            ['TranslateY', 0.9, 9, 'TranslateY', 0.7, 9],
            ['AutoContrast', 0.9, 2, 'Solarize', 0.8, 3],
            ['Equalize', 0.8, 8, 'Invert', 0.1, 3],
            ['TranslateY', 0.7, 9, 'AutoContrast', 0.9, 1],
        ] 
開發者ID:ngessert,項目名稱:isic2019,代碼行數:30,代碼來源:auto_augment.py


注:本文中的PIL.ImageEnhance.Brightness方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。