图片消噪与灰度处理

图片消噪

scipy.fftpack模块用来计算快速傅里叶变换
速度比传统傅里叶变换更快,是对之前算法的改进
图片是二维数据,注意使用fftpack的二维转变方法

moon = plt.imread('moonlanding.png')
plt.figure(figsize=(12,8))
plt.imshow(moon, cmap=plt.cm.gray)  # 'gray'

加载图片
在这里插入图片描述

# fft2时域 --》频域
fft2_moon = fft2(moon)
# 定义一个阈值,用于表示波动的上限,超过这个值的波,认为可以滤掉
threshold = 2e3
fft2_moon[np.abs(fft2_moon) > threshold] = 0
# 把频域数据转换成时域数据,时域才能看到图像
temp = ifft2(fft2_moon)
# 把实数保留,虚数去除
real = np.real(temp)
plt.imshow(real,cmap=plt.cm.gray)

在这里插入图片描述

图像灰度处理

图像识别
数据清洗(灰度处理)
data = plt.imread('ss.jfif')
plt.imshow(data)

在这里插入图片描述

1. 聚合函数处理图像的灰度

在第三维上取max, min, mean中任意一种

plt.imshow(data.min(axis=2), cmap='gray')

在这里插入图片描述

2. 使用dot运算,完成消除颜色的维度

RGB权值 [0.1,0.6,0.3]

weight = np.array([0.1,0.6,0.3])
gray_image = np.dot(data, weight)/255.
plt.imshow(gray_image, cmap='gray')

在这里插入图片描述

发布了58 篇原创文章 · 获赞 0 · 访问量 482

猜你喜欢

转载自blog.csdn.net/qq_41170489/article/details/104010055
今日推荐