You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
644 B
16 lines
644 B
3 years ago
|
import cv2
|
||
|
import matplotlib.pyplot as plt
|
||
|
# 原始图像
|
||
|
img_gray = cv2.imread('D:/Python/SpatialProcessing/HistogramModification/img/cake.jpg', cv2.IMREAD_GRAYSCALE)
|
||
|
|
||
|
# 直方图修正
|
||
|
equ = cv2.equalizeHist(img_gray)
|
||
|
|
||
|
# 显示图像
|
||
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||
|
plt.subplot(221), plt.imshow(img_gray, cmap=plt.cm.gray), plt.title('原始图像'), plt.axis('off')
|
||
|
plt.subplot(222), plt.hist(img_gray.ravel(), 256), plt.title('灰度直方图')
|
||
|
plt.subplot(223), plt.imshow(equ, cmap=plt.cm.gray), plt.title('修正图像'), plt.axis('off')
|
||
|
plt.subplot(224), plt.hist(equ.ravel(), 256), plt.title('修正直方图')
|
||
|
plt.show()
|