亮度变大了
原图
结果
# -*- coding: utf-8 -*-
import sysimport cv2
import numpy as np#加载图像
input_file = 'sunrise.jpg'#sys.argv[1]
img = cv2.imread(input_file)# 转灰度图
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('Input grayscale image', img_gray)# 均衡化直方图
img_gray_histeq = cv2.equalizeHist(img_gray)
cv2.imshow('Histogram equalized - grayscale', img_gray_histeq)# 均衡彩色直方图
img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
# y通道 - Y 表示亮度(Luminance、缩写Luma),即为灰度值
# U 和 V 表示色度(Chrominance、缩写Chroma),即为色调和饱和度
img_yuv[:,:,0] = cv2.equalizeHist(img_yuv[:,:,0])img_histeq = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
# 展示
cv2.imshow('Input color image', img)
cv2.imshow('Histogram equalized - color', img_histeq)cv2.waitKey()
标签:gray,img,均衡化,imshow,cv2,yuv,直方图,240724,histeq
From: https://blog.51cto.com/u_15862653/11888520