标签:16px 转换 white class 预览 size windows bytes red
美白、磨皮、搞笑图片处理
PIL库学习总结:
PIL库支持图像存储、显示和处理,它能够处理几乎所有图片格式,可以完成对图像的缩放、剪裁、叠加以及向图像添加线条、图像和文字等操作。
1、功能:
(1)图像归档:对图像进行批处理、生成图像预览、图像格式转换等;
(2)图像处理:图像基本处理、像素处理、颜色处理等。
2、分类:(主要讨论image)
Image类:from PIL import Image
方法 | 描述 |
Image.open(filename) | 根据参数加载图像文件 |
Image.new(mode,size,color) | 根据给定参数创建一个新的图像 |
Image.frombytes(mode,size,data) | 根据像素点data创建图像 |
Image.verify() | 对图像文件完整性进行检查,返回异常 |
from PIL import Image im = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") # 读取图片 im.show() # 可视化
美白磨皮:
from PIL import Image from PIL import ImageEnhance import cv2 import numpy as np # image = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") #image.show() def BrightnessEnhancement(brightness): image = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") enh_bri = ImageEnhance.Brightness(image) # brightness =1.5 image_brightened = enh_bri.enhance(brightness) image_brightened.show() def ContrastEnhancement(contrast): image = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") enh_con = ImageEnhance.Contrast(image) # contrast =1.5 image_contrasted = enh_con.enhance(contrast) image_contrasted.show() def ColorEnhancement(color): image = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") enh_col = ImageEnhance.Color(image) # color =0.8 image_colored = enh_col.enhance(color) image_colored.show() def SharpnessEnhancement(sharpness): image = Image.open("C:\\Users\\ZK\\Desktop\\test1.jpg") enh_sha = ImageEnhance.Sharpness(image) # sharpness = 2 image_sharped = enh_sha.enhance(sharpness) image_sharped.show() def Filter(image): image =cv2.imread("C:\\Users\\ZK\\Desktop\\test1.jpg") Remove=cv2.bilateralFilter(image,0,0,10) cv2.imshow(‘filter‘,Remove) cv2.waitKey(0) cv2.destroyAllWindows() # res = np.uint8(np.clip((1.2 * image + 10), 0, 255)) # tmp = np.hstack((dst, res)) # cv2.imshow(‘bai‘,res) def WhiteBeauty(image,whi): image =cv2.imread("C:\\Users\\ZK\\Desktop\\test1.jpg") white = np.uint8(np.clip((whi * image + 50), 0, 255)) cv2.imshow(‘bai‘,white) cv2.waitKey(0) cv2.destroyAllWindows() if __name__ =="__main__": filepath = "C:\\Users\\ZK\\Desktop\\test1.jpg" #原始图像 brightness = 1.5 contrast = 0.2 color=1.9 sharpness=0.1 BrightnessEnhancement(brightness) ContrastEnhancement(contrast) ColorEnhancement(color) SharpnessEnhancement(sharpness) whi = 1.2 image =cv2.imread("C:\\Users\\ZK\\Desktop\\test1.jpg") Filter(image) WhiteBeauty(image,whi)
原图:
美白:
标签:16px 转换 white class 预览 size windows bytes red
原文地址:https://www.cnblogs.com/linantelope/p/12729358.html