歸一化
將數(shù)組歸一化到0,1之間
array_out = cv2.normalize(array,None,0,1,cv2.NORM_MINMAX,cv2.CV_32F)
也可以使用下面的方法:
array = array - np.amin(array)
array = array / np.amax(array)
色彩轉(zhuǎn)化
Opencv使用了如下轉(zhuǎn)化公式將rgb圖像轉(zhuǎn)化為灰度(亮度)圖像
RGB2GRAY
img_gray = cv2.cvtColor(img_rgb,cv2.COLOR_RGB2GRAY)
如果需要將灰度(亮度)圖像轉(zhuǎn)化回彩色圖像症歇,可以使用如下公式:
GRAY2
其中嫩挤,Lin為原圖像的亮度值,Lout的轉(zhuǎn)換后亮度值乏奥,Cin為原圖像的r,g,b值。
def gray2rgb(lum_before,lum_after,rgb,s):
lum_before = np.repeat(lum_before[:,:,np.newaxis],3,axis=2)
lum_after = np.repeat(lum_after[:,:,np.newaxis],3,axis=2)
rgb_out = (rgb / lum_before)**s*lum_after
return rgb_out