本文整理匯總了Python中PIL.ImageEnhance.Sharpness方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageEnhance.Sharpness方法的具體用法?Python ImageEnhance.Sharpness怎麽用?Python ImageEnhance.Sharpness使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.ImageEnhance
的用法示例。
在下文中一共展示了ImageEnhance.Sharpness方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _fry
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [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
示例2: image_sharpness
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def image_sharpness(self, factor: int, extension: str = "png"):
"""Change image sharpness
Args:
factor (int): Factor to increase the sharpness 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.Sharpness(image).enhance(factor)
enhanced.save(fh, extension)
self.state = fh.getvalue()
return self
示例3: modifyImageBscc
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [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
示例4: save_img
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [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
示例5: random_sharpness
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def random_sharpness(image, jitter=.5):
"""
Random adjust sharpness for image
# Arguments
image: origin image for sharpness change
PIL Image object containing image data
jitter: jitter range for random sharpness,
scalar to control the random sharpness level.
# Returns
new_image: adjusted PIL Image object.
"""
enh_sha = ImageEnhance.Sharpness(image)
sharpness = rand(jitter, 1/jitter)
new_image = enh_sha.enhance(sharpness)
return new_image
示例6: __init__
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [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],
]
示例7: sharpness
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def sharpness(img, magnitude):
magnitudes = np.linspace(0.1, 1.9, 11)
img = ImageEnhance.Sharpness(img).enhance(random.uniform(magnitudes[magnitude], magnitudes[magnitude+1]))
return img
示例8: __call__
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def __call__(self, image, label):
#aug blur
if random.random() > set_ratio:
select = random.random()
if select < 0.3:
kernalsize = random.choice([3, 5])
image = cv2.GaussianBlur(image, (kernalsize, kernalsize), 0)
elif select < 0.6:
kernalsize = random.choice([3, 5])
image = cv2.medianBlur(image, kernalsize)
else:
kernalsize = random.choice([3, 5])
image = cv2.blur(image, (kernalsize, kernalsize))
# aug noise
if random.random() > set_ratio:
mu = 0
sigma = random.random() * 10.0
image = np.array(image, dtype=np.float32)
image += np.random.normal(mu, sigma, image.shape)
image[image > 255] = 255
image[image < 0] = 0
# aug_color
if random.random() > set_ratio:
random_factor = np.random.randint(4, 17) / 10.
color_image = ImageEnhance.Color(image).enhance(random_factor)
random_factor = np.random.randint(4, 17) / 10.
brightness_image = ImageEnhance.Brightness(color_image).enhance(random_factor)
random_factor = np.random.randint(6, 15) / 10.
contrast_image = ImageEnhance.Contrast(brightness_image).enhance(random_factor)
random_factor = np.random.randint(8, 13) / 10.
image = ImageEnhance.Sharpness(contrast_image).enhance(random_factor)
return np.array(image), label
示例9: test_sharpness_with_PIL
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def test_sharpness_with_PIL(factor):
np.random.seed(0)
image = np.random.randint(low=0, high=255, size=(10, 5, 5, 3), dtype=np.uint8)
sharpened = np.stack(
[ImageEnhance.Sharpness(Image.fromarray(i)).enhance(factor) for i in image]
)
np.testing.assert_allclose(
color_ops.sharpness(tf.constant(image), factor).numpy(), sharpened, atol=1
)
示例10: test_sanity
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def test_sanity(self):
# FIXME: assert_image
# Implicit asserts no exception:
ImageEnhance.Color(hopper()).enhance(0.5)
ImageEnhance.Contrast(hopper()).enhance(0.5)
ImageEnhance.Brightness(hopper()).enhance(0.5)
ImageEnhance.Sharpness(hopper()).enhance(0.5)
示例11: test_crash
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def test_crash(self):
# crashes on small images
im = Image.new("RGB", (1, 1))
ImageEnhance.Sharpness(im).enhance(0.5)
示例12: test_alpha
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def test_alpha(self):
# Issue https://github.com/python-pillow/Pillow/issues/899
# Is alpha preserved through image enhancement?
original = self._half_transparent_image()
for op in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
for amount in [0, 0.5, 1.0]:
self._check_alpha(
getattr(ImageEnhance, op)(original).enhance(amount),
original, op, amount)
示例13: __call__
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def __call__(self, img):
factor = 1.0 + np.random.randn(1)/5
# print("sharpness {}".format(factor))
enhancer = ImageEnhance.Sharpness(img)
return enhancer.enhance(factor)
示例14: _videofry
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def _videofry(img, duration):
imgs = []
frame = 0
while img:
i = img.copy()
i = i.convert('RGB')
e = ImageEnhance.Sharpness(i)
i = e.enhance(100)
e = ImageEnhance.Contrast(i)
i = e.enhance(100)
e = ImageEnhance.Brightness(i)
i = e.enhance(.27)
r, g, b = i.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)
e = ImageEnhance.Contrast(b)
i = Image.merge('RGB', (r, g, b))
e = ImageEnhance.Brightness(i)
i = e.enhance(1.5)
imgs.append(i)
frame += 1
try:
img.seek(frame)
except EOFError:
break
temp = BytesIO()
temp.name = 'deepfried.gif'
if duration:
imgs[0].save(temp, format='GIF', save_all=True, append_images=imgs[1:], loop=0, duration=duration)
else:
imgs[0].save(temp, format='GIF', save_all=True, append_images=imgs[1:], loop=0)
temp.seek(0)
return temp
示例15: _nuke
# 需要導入模塊: from PIL import ImageEnhance [as 別名]
# 或者: from PIL.ImageEnhance import Sharpness [as 別名]
def _nuke(img):
w, h = img.size[0], img.size[1]
dx = ((w+200)//200)*2
dy = ((h+200)//200)*2
img = img.resize(((w+1)//dx,(h+1)//dy))
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)
e = ImageEnhance.Sharpness(img)
img = e.enhance(100)
img = img.resize((w,h),Image.BILINEAR)
temp = BytesIO()
temp.name = 'nuke.jpg'
img.save(temp, quality=1)
temp.seek(0)
return temp