小程序_USM_selection

目的:用USM(非锐化掩膜)对图像进行处理,是图像的颜色信息更为尖锐,得到丰富的图像高维信息。

平台:python + opencv

import cv2
import numpy as np

img = cv2.imread('C:/Users/PC/Desktop/new1-2018-06-02-14-28-04.jpg') #低反光
cv2.imshow('image',img)

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

#B = np.zeros(R.shape[:2])
#G = np.zeros(R.shape[:2])
#
#img1 = cv2.merge([B.astype(np.uint8), G.astype(np.uint8), R.astype(np.uint8)])
#cv2.imshow('image1',img1)

img = cv2.imread('C:/Users/PC/Desktop/new1-2018-06-02-14-28-04.jpg') #低反光
cv2.imshow("img", img)
#gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#roi = ROI_detect.ROI_Detection(gray) #检查人脸
#cv2.imshow("roi", roi)

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)  
      
# =============================================================================
# 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/80563429
今日推荐