python用opencv 图像傅里叶变换
作者:我坚信阳光灿烂 时间:2021-03-02 02:04:35
傅里叶变换
dft = cv.dft(np.float32(img),flags = cv.DFT_COMPLEX_OUTPUT)
傅里叶逆变换
img_back = cv.idft(f_ishift)
实验:将图像转换到频率域,低通滤波,将频率域转回到时域,显示图像
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('d:/paojie_g.jpg',0)
rows, cols = img.shape
crow, ccol = rows//2 , cols//2
dft = cv.dft(np.float32(img),flags = cv.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
# create a mask first, center square is 1, remaining all zeros
mask = np.zeros((rows,cols,2),np.uint8)
mask[crow-30:crow+31, ccol-30:ccol+31, :] = 1
# apply mask and inverse DFT
fshift = dft_shift*mask
f_ishift = np.fft.ifftshift(fshift)
img_back = cv.idft(f_ishift)
img_back = cv.magnitude(img_back[:,:,0],img_back[:,:,1])
plt.subplot(121),plt.imshow(img, cmap = 'gray')
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(img_back, cmap = 'gray')
plt.title('Low Pass Filter'), plt.xticks([]), plt.yticks([])
plt.show()
来源:https://www.cnblogs.com/wojianxin/p/12684306.html
标签:python,图像,傅里叶变换,opencv
0
投稿
猜你喜欢
PHP结合vue导出excel出现乱码的解决方法分享
2023-05-30 09:18:25
Python格式化输出字符串方法小结【%与format】
2023-01-06 00:01:50
利用XMLHTTP检测网址及探测服务器类型
2009-04-24 15:12:00
FF下,用 col 隐藏表格列的方法详解!
2008-04-02 11:35:00
sqlserver中重复数据值只取一条的sql语句
2012-06-06 19:46:31
unplugin-auto-import的配置以及eslint报错解决详解
2024-05-10 14:09:10
详解Vue中使用v-for语句抛出错误的解决方案
2024-04-09 10:44:34
Python图像处理库crop()函数 thumbnail方法使用详解
2022-12-26 05:57:46
python中如何写类
2023-09-02 18:19:58
MySQL中row_number的实现过程
2024-01-23 15:08:54
sqlserver 快速生成汉字的首拼字母的函数(经典)
2012-06-06 20:16:41
Python恋爱小助手之必拿下
2023-09-22 13:09:00
django 连接数据库 sqlite的例子
2023-08-03 19:03:15
让你同时上传 1000 个文件 (二)
2023-11-14 10:22:52
在ASP.NET 2.0中操作数据之四:使用ObjectDataSource展现数据
2024-05-13 09:15:45
pandas 把数据写入txt文件每行固定写入一定数量的值方法
2021-06-13 20:08:14
python3+opencv生成不规则黑白mask实例
2023-10-06 11:01:25
Python中导入模块的几种方式总结
2023-08-04 17:03:54
SQL Substring提取部分字符串
2024-01-14 20:03:07
ionic在开发ios系统微信时键盘挡住输入框的解决方法(键盘弹出问题)
2024-05-02 16:18:12