PYTHON 人像美顏

2021-08-27 08:54:50 字數 3607 閱讀 4516

功能:影象基礎調整: 影象的亮度、對比度、色度,增強影象的銳度,美白,磨皮

# 影象基礎調整: 影象的亮度、對比度、色度,還可以用於增強影象的銳度,美白

# #亮度增強 :brightness在(0-1)之間,新影象較原圖暗,在(1-~)新影象較原圖亮 ,

# ##brightness=1,保持原影象不變;可自定義引數範圍

# '''

image = image.open(filepath)

enh_bri = imageenhance.brightness(image)

# brightness =1.5

image_brightened = enh_bri.enhance(brightness)

image_brightened.show()

defcontrastenhancement

(contrast):

# '''

# #對比度增強: 可自定義引數contrast範圍,contrast=1,保持原影象不變

# '''

image = image.open(filepath)

enh_con = imageenhance.contrast(image)

# contrast =1.5

image_contrasted = enh_con.enhance(contrast)

image_contrasted.show()

defcolorenhancement

(color):

# '''

# #色度增強 : 飽和度 color=1,保持原影象不變

# '''

image = image.open(filepath)

enh_col = imageenhance.color(image)

# color =0.8

image_colored = enh_col.enhance(color)

image_colored.show()

defsharpnessenhancement

(sharpness):

# '''

# #銳度增強: 清晰度 sharpness=1,保持原影象不變

# '''

image = image.open(filepath)

enh_sha = imageenhance.sharpness(image)

# sharpness = 2

image_sharped = enh_sha.enhance(sharpness)

image_sharped.show()

deffilter

(image):

# """

# 色彩窗的半徑

# 影象將呈現類似於磨皮的效果

# """

#image:輸入影象,可以是mat型別,

# 影象必須是8位或浮點型單通道、三通道的影象

#0:表示在過濾過程中每個畫素鄰域的直徑範圍,一般為0

#後面兩個數字:空間高斯函式標準差,灰度值相似性標準差

image =cv2.imread(filepath)

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)

defwhitebeauty

(image,whi):

# '''

# 美白

# '''

import cv2

image =cv2.imread(filepath)

white = np.uint8(np.clip((whi * image + 10), 0, 255))

cv2.imshow('bai',white)

cv2.waitkey(0)

cv2.destroyallwindows()

# cv2.imwrite('/home/260207/桌面/photo/15-1.jpg',dst)

#原始影象

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('/home/260207/桌面/photo/11-1.jpg')

filter(image)

whitebeauty(image,whi)

原影象

磨皮影象:

亮度增強:

色彩度(飽和度)增強:

python人像美顏 人像美顏美妝演算法入門必備

推薦3 本書不使用opencv matlab等第三方庫或工具介面,也沒有使用python等高階語言,而是直接使用最簡單的c語言來實現所有演算法,具有較強的跨平台性和演算法學習性。對於任何乙個初學者而言,最佳的學習方法就是掌握演算法進而用 實現演算法,而不是對演算法一知半解的情況下,直接呼叫第三方介面...

mysql人像伴隨模型 人像美顏演算法 面板檢測

為什麼要進行 檢測 美顏的核心處理是磨皮,僅進行模糊平滑處理,對整張影象的處理會顯得比較假,如果能針對性的只處理 效果會更真實。真實的工程應用中,一張影象的磨皮處理,會分兩步走 檢測出 生成乙個maska 保邊濾波得到影象t 根據maska,僅對 部位進行濾波處理,非 採用原影象素 檢測 or 人像...

python實現人像動漫化

技術文件 client id 為官網獲取的ak,client secret 為官網獲取的sk host 官網獲取的ak client secret 官網獲取的sk response requests.get host if response access token response.json ac...