要使用Python和PIL库使图像亮度均匀,请按照以下步骤操作:
pip install pillow
from PIL import Image
from PIL import ImageEnhance
image = Image.open("path/to/your/image.jpg")
enhancer = ImageEnhance.Brightness(image)
enhanced_image = enhancer.enhance(1.5) # 1.0为原始亮度,2.0为原始亮度的两倍,可以根据需要调整数值
enhanced_image.save("path/to/save/enhanced_image.jpg")
enhanced_image.show()
完整代码示例:
from PIL import Image
from PIL import ImageEnhance
image = Image.open("path/to/your/image.jpg")
enhancer = ImageEnhance.Brightness(image)
enhanced_image = enhancer.enhance(1.5)
enhanced_image.save("path/to/save/enhanced_image.jpg")
enhanced_image.show()
这个代码示例将打开指定路径的图像,使用ImageEnhance库的Brightness类增强图像亮度,并将增强后的图像保存到指定路径并显示出来。
领取专属 10元无门槛券
手把手带您无忧上云