前言
这是图像增强部分的最后一点内容,因为在《指数增强》中说过,除了指数增强有FPGA,所以其他几个方法只讲Python,懂原理即可。
一、图像灰度转换
图像灰度处理很简单,把图像的红色、绿色、蓝色通道像素乘上相应的系数再加和。公式如下。
g r a y = r e d × 0.299 + g r e e n × 0.587 + b l u e × 0.114 gray = red \times 0.299 + green \times 0.587 + blue \times 0.114 gray=red×0.299+green×0.587+blue×0.114
import numpy as np
import matplotlib.pyplot as plt
img = plt.imread("lenna.png")
gray = 0.299 * img[:, :, 0] + 0.587 * img[:, :, 1] + 0.114 * img[:, :, 2]
gray *= 255
gray = gray.astype(np.uint8)
#以下用严谨的方式画图
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(1,2,1)
ax.set_title("raw image")
ax.set_xlabel("width")
ax.set_ylabel("height")
plt.imshow

本文介绍了如何使用Python进行图像灰度处理,通过公式计算像素值占比和累加,然后实现直方图均衡化,提升图像对比度。最后总结了图像增强的内容并预告了下一部分:图像降噪算法。
最低0.47元/天 解锁文章
1975

被折叠的 条评论
为什么被折叠?



