步骤:
第 1 步:手动均衡
第 2 步:通过使用 OpenCV 函数
什么是图像直方图?
它是图像强度分布的图形表示。它量化了所考虑的每个强度值的像素数。
第 1 步:手动均衡
%matplotlib inline
from IPython.display import display, Math, Latex
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
img = Image.open('DATA/einstein.jpg')
plt.imshow(img)
输出:
<matplotlib.image.AxesImage at 0x1d0b37d2250>
显示彩色图像
将图像转换为 numpy 数组,以便 OpenCV 可以使用:
img = np.asanyarray(img)
img.shape
输出:
(2354, 2560, 3)
将 RGB 转换为灰度:
import cv2
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img.shape
输出:
(2354, 2560)
显示图像:
plt.imshow(img, cmap='gray')
输出:
<matplotlib.image.AxesImage at 0x1d0b415e100>
我们现在知道如何处理直方图了
img.max()
输出:
255
img.min()