本文整理匯總了Python中PIL.ImageOps.equalize方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageOps.equalize方法的具體用法?Python ImageOps.equalize怎麽用?Python ImageOps.equalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.ImageOps
的用法示例。
在下文中一共展示了ImageOps.equalize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: preprocessing_fn
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def preprocessing_fn(img):
img_size = 48
img_out = []
for im in img:
img_eq = ImageOps.equalize(Image.fromarray(im))
width, height = img_eq.size
min_side = min(img_eq.size)
center = width // 2, height // 2
left = center[0] - min_side // 2
top = center[1] - min_side // 2
right = center[0] + min_side // 2
bottom = center[1] + min_side // 2
img_eq = img_eq.crop((left, top, right, bottom))
img_eq = np.array(img_eq.resize([img_size, img_size]))
img_out.append(img_eq)
return np.array(img_out, dtype=np.float32)
示例2: classify_ahash
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
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)
示例3: __call__
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def __call__(self, image):
"""
Apply a visual effect on the image.
Args
image: Image to adjust
"""
random_enhance_id = np.random.randint(0, 4)
if random_enhance_id == 0:
image = color(image, prob=self.color_prob, factor=self.color_factor)
elif random_enhance_id == 1:
image = contrast(image, prob=self.contrast_prob, factor=self.contrast_factor)
elif random_enhance_id == 2:
image = brightness(image, prob=self.brightness_prob, factor=self.brightness_factor)
else:
image = sharpness(image, prob=self.sharpness_prob, factor=self.sharpness_factor)
random_ops_id = np.random.randint(0, 3)
if random_ops_id == 0:
image = autocontrast(image, prob=self.autocontrast_prob)
elif random_ops_id == 1:
image = equalize(image, prob=self.equalize_prob)
else:
image = solarize(image, prob=self.solarize_prob, threshold=self.solarize_threshold)
return image
示例4: equalize
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def equalize(img, magnitude):
img = ImageOps.equalize(img)
return img
示例5: __init__
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def __init__(self, fillcolor=(128, 128, 128)):
self.policies = [
SubPolicy(0.4, "posterize", 8, 0.6, "rotate", 9, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.8, "equalize", 8, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.6, "posterize", 7, 0.6, "posterize", 6, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.4, "equalize", 4, 0.8, "rotate", 8, fillcolor),
SubPolicy(0.6, "solarize", 3, 0.6, "equalize", 7, fillcolor),
SubPolicy(0.8, "posterize", 5, 1.0, "equalize", 2, fillcolor),
SubPolicy(0.2, "rotate", 3, 0.6, "solarize", 8, fillcolor),
SubPolicy(0.6, "equalize", 8, 0.4, "posterize", 6, fillcolor),
SubPolicy(0.8, "rotate", 8, 0.4, "color", 0, fillcolor),
SubPolicy(0.4, "rotate", 9, 0.6, "equalize", 2, fillcolor),
SubPolicy(0.0, "equalize", 7, 0.8, "equalize", 8, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor),
SubPolicy(0.8, "rotate", 8, 1.0, "color", 2, fillcolor),
SubPolicy(0.8, "color", 8, 0.8, "solarize", 7, fillcolor),
SubPolicy(0.4, "sharpness", 7, 0.6, "invert", 8, fillcolor),
SubPolicy(0.6, "shearX", 5, 1.0, "equalize", 9, fillcolor),
SubPolicy(0.4, "color", 0, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor),
SubPolicy(0.8, "equalize", 8, 0.6, "equalize", 3, fillcolor)
]
示例6: test_equalize_dtype_shape
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def test_equalize_dtype_shape(dtype, shape):
image = np.ones(shape=shape, dtype=dtype)
equalized = color_ops.equalize(tf.constant(image)).numpy()
np.testing.assert_equal(equalized, image)
assert equalized.dtype == image.dtype
示例7: test_equalize_with_PIL
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def test_equalize_with_PIL():
np.random.seed(0)
image = np.random.randint(low=0, high=255, size=(4, 3, 3, 3), dtype=np.uint8)
equalized = np.stack([ImageOps.equalize(Image.fromarray(i)) for i in image])
np.testing.assert_equal(color_ops.equalize(tf.constant(image)).numpy(), equalized)
示例8: test_equalize_channel_first
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def test_equalize_channel_first(shape):
image = tf.ones(shape=shape, dtype=tf.uint8)
equalized = color_ops.equalize(image, "channels_first")
np.testing.assert_equal(equalized.numpy(), image.numpy())
示例9: equalize
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def equalize(pil_img, _):
return ImageOps.equalize(pil_img)
示例10: test_1pxfit
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def test_1pxfit(self):
# Division by zero in equalize if image is 1 pixel high
newimg = ImageOps.fit(hopper("RGB").resize((1, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
newimg = ImageOps.fit(hopper("RGB").resize((1, 100)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
newimg = ImageOps.fit(hopper("RGB").resize((100, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
示例11: test_pil163
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def test_pil163(self):
# Division by zero in equalize if < 255 pixels in image (@PIL163)
i = hopper("RGB").resize((15, 16))
ImageOps.equalize(i.convert("L"))
ImageOps.equalize(i.convert("P"))
ImageOps.equalize(i.convert("RGB"))
示例12: __init__
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def __init__(self, fillcolor=(128, 128, 128)):
self.policies = [
SubPolicy(0.4, "posterize", 8, 0.6, "rotate", 9, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.8, "equalize", 8, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.6, "posterize", 7, 0.6, "posterize", 6, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.4, "equalize", 4, 0.8, "rotate", 8, fillcolor),
SubPolicy(0.6, "solarize", 3, 0.6, "equalize", 7, fillcolor),
SubPolicy(0.8, "posterize", 5, 1.0, "equalize", 2, fillcolor),
SubPolicy(0.2, "rotate", 3, 0.6, "solarize", 8, fillcolor),
SubPolicy(0.6, "equalize", 8, 0.4, "posterize", 6, fillcolor),
SubPolicy(0.8, "rotate", 8, 0.4, "color", 0, fillcolor),
SubPolicy(0.4, "rotate", 9, 0.6, "equalize", 2, fillcolor),
SubPolicy(0.0, "equalize", 7, 0.8, "equalize", 8, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor),
SubPolicy(0.8, "rotate", 8, 1.0, "color", 2, fillcolor),
SubPolicy(0.8, "color", 8, 0.8, "solarize", 7, fillcolor),
SubPolicy(0.4, "sharpness", 7, 0.6, "invert", 8, fillcolor),
SubPolicy(0.6, "shearX", 5, 1.0, "equalize", 9, fillcolor),
SubPolicy(0.4, "color", 0, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor)
]
示例13: equalize
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def equalize(img, **__):
return ImageOps.equalize(img)
示例14: __init__
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def __init__(self, total_iter, fillcolor=(128, 128, 128)):
self.total_iter = total_iter
self.gamma = 0
self.policies = [
SubPolicy(0.4, "posterize", 8, 0.6, "rotate", 9, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.8, "equalize", 8, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.6, "posterize", 7, 0.6, "posterize", 6, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.4, "equalize", 4, 0.8, "rotate", 8, fillcolor),
SubPolicy(0.6, "solarize", 3, 0.6, "equalize", 7, fillcolor),
SubPolicy(0.8, "posterize", 5, 1.0, "equalize", 2, fillcolor),
SubPolicy(0.2, "rotate", 3, 0.6, "solarize", 8, fillcolor),
SubPolicy(0.6, "equalize", 8, 0.4, "posterize", 6, fillcolor),
SubPolicy(0.8, "rotate", 8, 0.4, "color", 0, fillcolor),
SubPolicy(0.4, "rotate", 9, 0.6, "equalize", 2, fillcolor),
SubPolicy(0.0, "equalize", 7, 0.8, "equalize", 8, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor),
SubPolicy(0.8, "rotate", 8, 1.0, "color", 2, fillcolor),
SubPolicy(0.8, "color", 8, 0.8, "solarize", 7, fillcolor),
SubPolicy(0.4, "sharpness", 7, 0.6, "invert", 8, fillcolor),
SubPolicy(0.6, "shearX", 5, 1.0, "equalize", 9, fillcolor),
SubPolicy(0.4, "color", 0, 0.6, "equalize", 3, fillcolor),
SubPolicy(0.4, "equalize", 7, 0.2, "solarize", 4, fillcolor),
SubPolicy(0.6, "solarize", 5, 0.6, "autocontrast", 5, fillcolor),
SubPolicy(0.6, "invert", 4, 1.0, "equalize", 8, fillcolor),
SubPolicy(0.6, "color", 4, 1.0, "contrast", 8, fillcolor),
SubPolicy(0.8, "equalize", 8, 0.6, "equalize", 3, fillcolor)
]
示例15: equalize
# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import equalize [as 別名]
def equalize(pil_img, *args):
return ImageOps.equalize(pil_img)