对图像进行非锐化掩膜(USM),并多次增强

# -*- coding: utf-8 -*-
"""
Created on Tue May  8 19:11:52 2018

@author: PC
"""
import cv2
import numpy as np

img = cv2.imread("C:/Users/PC/Desktop/program/skin/Images/chendingxin1.jpg")

B, G, R = cv2.split(img)
cv2.imshow("B", B)
cv2.imshow("G", G)
cv2.imshow("R", R)

cv2.imshow("img", img)

img_HSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #提取V通道
H, S, V = cv2.split(img_HSV)
cv2.imshow('V',V)
    
B, G, R = cv2.split(img)
# =============================================================================
# 去除光照不均
# =============================================================================
#kernel = np.ones((11,11),np.float32)/121 
#mask = cv2.filter2D(V,-1,kernel) # V通道均值
#mask1 = (mask/256) * (mask/256) * 256 # 建立函数,使低值像素分布更细腻,抛物线函数
#mask2 = mask1.astype(np.uint8)
#V1 = cv2.normalize(mask2, None, 0, 125, cv2.NORM_MINMAX) #归一化,数值分布到 range(0,100)
#cv2.imshow('mask1',V1)
#B = cv2.subtract(B, V1)
#G = cv2.subtract(G, V1)
#R = cv2.subtract(R, V1)
#dst = cv2.merge((B,G,R))
#dst = cv2.normalize(dst, None, 0, 255, cv2.NORM_MINMAX)
#cv2.imshow("light", dst)  
dst = img      
# =============================================================================
# USM
# =============================================================================
dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 2, dst1, -1, 0);
cv2.imshow("image_enhance1", img_enhance)    

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 3, dst1, -2, 0);
cv2.imshow("image_enhance2", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 4, dst1, -3, 0);
cv2.imshow("image_enhance3", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 5, dst1, -4, 0);
cv2.imshow("image_enhance4", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 6, dst1, -5, 0);
cv2.imshow("image_enhance5", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 7, dst1, -6, 0);
cv2.imshow("image_enhance6", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 8, dst1, -7, 0);
cv2.imshow("image_enhance7", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 9, dst1, -8, 0);
cv2.imshow("image_enhance8", img_enhance) 

dst1 = cv2.GaussianBlur(dst, (101, 101), 100) 
img_enhance = cv2.addWeighted(dst, 10, dst1, -9, 0);
cv2.imshow("image_enhance9", img_enhance) 

cv2.waitKey(0)
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/weixin_39153202/article/details/82425327