直方图均衡化

#直方图均衡化函数:equalizeHist(图像),只能对单通道进行均衡化
import cv2
import numpy as np
img = cv2.imread('D:/pythonob/imageinpaint/img/flower.jpg',1)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
grayEq = cv2.equalizeHist(gray)#灰度图像直方图均衡化
#BGR彩色图像均衡化
(b,g,r) = cv2.split(img)#图像通道分解
Eb = cv2.equalizeHist(b)
Eg = cv2.equalizeHist(g)
Er = cv2.equalizeHist(r)
BGRresult = cv2.merge((Eb,Eg,Er))#图像通道合并
#YUV彩色图像均衡化
imgYUV = cv2.cvtColor(img,cv2.COLOR_BGR2YCrCb)#转化为YVU图像
channelYVU = cv2.split(imgYUV)
channelYVU[0] = cv2.equalizeHist(channelYVU[0])
channels = cv2.merge(channelYVU)
YUVresult = cv2.cvtColor(channels,cv2.COLOR_YCR_CB2BGR)

cv2.imshow('src',img)
cv2.imshow('gray',gray)
cv2.imshow('grayEq',grayEq)
cv2.imshow('BGRcolorEq',BGRresult)
cv2.imshow('YUVcolorEq',YUVresult)
cv2.waitKey(0)


效果图:

直方图均衡化

 

直方图均衡化

 

上一篇:【C语言细节】静态二维数组


下一篇:opencv-Mat函数