本文解释灰度直方图均衡化、彩色直方图均衡化和YUV均衡化效果
灰度直方图均衡化
import cv2
import numpy as np
img = cv2.imread('1.jpg', 1)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('src', img)
cv2.imshow('dst0 COLOR_BGR2GRAY', gray)
# 灰度图像的直方图均衡化
dst = cv2.equalizeHist(gray)
cv2.imshow('dst1 equalizeHist', dst)
cv2.waitKey(0)
效果如下:
image.png
彩色直方图均衡化
# 彩色直方图均衡化
import cv2
import numpy as np
img = cv2.imread('1.jpg', 1)
cv2.imshow('src', img)
(b, g, r) = cv2.split(img) # 通道分解
bH = cv2.equalizeHist(b)
gH = cv2.equalizeHist(g)
rH = cv2.equalizeHist(r)
result = cv2.merge((bH, gH, rH)) # 通道合成
cv2.imshow('dst2', result)
cv2.waitKey(0)
效果如下:
image.png
YUV均衡化
import cv2
import numpy as np
img = cv2.imread('1.jpg', 1)
cv2.imshow('src', img)
# YCrCb即YUV,主要用于优化彩色视频信号的传输
imgYUV = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
channelYUV = cv2.split(imgYUV) # 分解通道
channelYUV[0] = cv2.equalizeHist(channelYUV[0])
channels = cv2.merge(channelYUV) # 合成通道
result = cv2.cvtColor(channels, cv2.COLOR_YCrCb2BGR)
cv2.imshow('dst3', result)
cv2.waitKey(0)
效果如下:
image.png
网友评论