def Ra_space(img, Ra_ratio, a_threshold):
'''
Extract the Ra features by converting RGB to LAB space.
The higher is a value, the "redder" is the pixel.
'''
imgLab = cv2.cvtColor(img, cv2.COLOR_RGB2LAB);
w = img.shape[0]
h = img.shape[1]
Ra = np.zeros((w*h, 2))
for i in range(w):
for j in range(h):
R = math.sqrt((w/2-i)*(w/2-i) + (h/2-j)*(h/2-j))
Ra[i*h+j, 0] = R
Ra[i*h+j, 1] = min(imgLab[i][j][1], a_threshold)
Ra[:,0] /= max(Ra[:,0])
Ra[:,0] *= Ra_ratio
Ra[:,1] /= max(Ra[:,1])
return Ra
评论列表
文章目录