OpenCV之图像直方图均衡化
Posted MachineLP
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV之图像直方图均衡化相关的知识,希望对你有一定的参考价值。
python代码:
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
def custom_hist(gray):
h, w = gray.shape
hist = np.zeros([256], dtype=np.int32)
for row in range(h):
for col in range(w):
pv = gray[row, col]
hist[pv] += 1
y_pos = np.arange(0, 256, 1, dtype=np.int32)
plt.bar(y_pos, hist, align=\'center\', color=\'r\', alpha=0.5)
plt.xticks(y_pos, y_pos)
plt.ylabel(\'Frequency\')
plt.title(\'Histogram\')
plt.show()
src = cv.imread("./test.png")
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", gray)
dst = cv.equalizeHist(gray)
cv.imshow("eh", dst)
custom_hist(gray)
custom_hist(dst)
cv.waitKey(0)
cv.destroyAllWindows()
以上是关于OpenCV之图像直方图均衡化的主要内容,如果未能解决你的问题,请参考以下文章