拿到一张图片后,想不采用机器学习就对其高光部分进行识别,采取 Specular Reflections Removal for Endoscopic Image Sequences With Adaptive-Rpca Decomposition 提出的方法,得到高光掩码矩阵,设定阈值后即可判定高光部分
# 设置的参数
threshold = 0.5 # 0-1之间
area = 0.01 # 高光的占比
ts = 0.35
tv = 0.85
def function_A(x):
return (1-np.exp(-2*pow(np.maximum(x, 0),2)/(0.01)))
def function_B(x):
return 1-np.exp(-2*pow(np.maximum(x, 0),2)/(0.01))
def function_C(x):
return (ts - x/256)
def function_D(x):
return (x/256 - tv)
def test(x):
return x * 256
def detect_highlight(path):
img = cv2.imread(path)
size = img.shape
w = size[1]
h = size[0]
# Convert BGR to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
saturation=hsv[:,:,1]
value=hsv[:,:,2]
a = function_A(function_C(saturation))
b = function_B(function_D(value))
res = a*b
return res