Python opencv实现图片的理想低通滤波
import CV2 import numpy as np
img = CV2.imread('input.jpg') # 读入图片 h, w = img.shape[:2] # 获取图片高度和宽度
构建理想低通滤波器
d0 = 50 # 我们设置半径为50 filt = np.zeros((h,w),np.float32) for i in range(h): for j in range(w): dist = np.sqrt((i-h//2)2 + (j-w//2)2) # 计算到中心点的距离 if dist <= d0: filt[i,j] = 1.0
转换为频域图像
freq = np.fft.fft2(img)
对频域图像进行滤波
filtered_freq = freq * filt
将频域图像还原为时域图像
filteredimg = np.fft.ifft2(filteredfreq) filteredimg = np.abs(filteredimg)
显示结果
CV2.imshow('Input', img) CV2.imshow('Result', filtered_img.astype(np.uint8)) CV2.waitKey(0) CV2.destroyAllWindows()
相关学习资料推荐,点击下方链接免费报名,先码住不迷路~】
音视频免费学习地址:FFmpeg/WebRTC/RTMP/NDK/Android音视频流媒体高级开发
【免费分享】音视频学习资料包、大厂面试题、技术视频和学习路线图,资料包括(C/C++,Linux,FFmpeg webRTC rtmp hls rtsp ffplay srs 等等)有需要的可以点击788280672加群免费领取~
