当前位置:网站首页>图像处理一百题(11-20)
图像处理一百题(11-20)
2022-07-06 09:29:00 【狗蛋儿l】
问题十一:均值滤波器
使用3*3的均值滤波器来进行滤波吧!
平滑线性空间滤波器的输出是包含在滤波器模板邻域内的像素的简单平均值,也就是均值滤波器。均值滤波器也是低通滤波器,均值滤波器很容易理解,即把邻域内的平均值赋给中心元素。
均值滤波器用来降低噪声,均值滤波器的主要应用是去除图像中的不相关细节,不相关是指与滤波器的模板相比较小的像素区域。模糊图片以便得到感兴趣物体的粗略描述,因此那些较小的物体的灰度就会与背景混合在一起,较大的物体则变的像斑点而易于检测。模板的大小由那些即将融入背景中的物体尺寸决定。
import cv2
import numpy as np
# mean filter
def mean_filter(img, K_size=3):
H, W, C = img.shape
# zero padding
pad = K_size // 2
out = np.zeros((H + pad * 2, W + pad * 2, C), dtype=np.float)
out[pad: pad + H, pad: pad + W] = img.copy().astype(np.float)
tmp = out.copy()
# filtering
for y in range(H):
for x in range(W):
for c in range(C):
out[pad + y, pad + x, c] = np.mean(tmp[y: y + K_size, x: x + K_size, c])
out = out[pad: pad + H, pad: pad + W].astype(np.uint8)
return out
# Read image
img = cv2.imread("jiaoyan.jpg")
# Mean Filter
out = mean_filter(img, K_size=3)
# Save result
cv2.imwrite("out.jpg", out)
cv2.imshow("result", out)
cv2.waitKey(0)
cv2.destroyAllWindows()
原图像
处理后图像
问题十二:Motion Filter
Motion Filter取对角线方向的像素的平均值,像下式这样定义:
import cv2
import numpy as np
# motion filter
def motion_filter(img, K_size=3):
H, W, C = img.shape
# Kernel
K = np.diag( [1] * K_size ).astype(np.float)
K /= K_size
# zero padding
pad = K_size // 2
out = np.zeros((H + pad * 2, W + pad * 2, C), dtype=np.float)
out[pad: pad + H, pad: pad + W] = img.copy().astype(np.float)
tmp = out.copy()
# filtering
for y in range(H):
for x in range(W):
for c in range(C):
out[pad + y, pad + x, c] = np.sum(K * tmp[y: y + K_size, x: x + K_size, c])
out = out[pad: pad + H, pad: pad + W].astype(np.uint8)
return out
# Read image
img = cv2.imread("jiaoyan.jpg")
# motion filtering
out = motion_filter(img, K_size=3)
# Save result
cv2.imwrite("out.jpg", out)
cv2.imshow("result", out)
cv2.waitKey(0)
cv2.destroyAllWindows()
边栏推荐
- Codeforces Round #800 (Div. 2)AC
- 简单尝试DeepFaceLab(DeepFake)的新AMP模型
- Research Report on hearing health care equipment industry - market status analysis and development prospect prediction
- Codeforces Round #801 (Div. 2)A~C
- 875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
- Li Kou - 298th weekly match
- Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
- Research Report on market supply and demand and strategy of Chinese table lamp industry
- 第6章 DataNode
- Li Kou: the 81st biweekly match
猜你喜欢
Oneforall installation and use
window11 conda安装pytorch过程中遇到的一些问题
Some problems encountered in installing pytorch in windows11 CONDA
1605. Sum the feasible matrix for a given row and column
807. Maintain the urban skyline
969. Pancake sorting
Codeforces Round #802(Div. 2)A~D
antd upload beforeUpload中禁止触发onchange
409. Longest palindrome
pytorch提取骨架(可微)
随机推荐
Summary of FTP function implemented by qnetworkaccessmanager
Codeforces Round #797 (Div. 3)无F
Log statistics (double pointer)
力扣:第81场双周赛
Codeforces Round #800 (Div. 2)AC
Share an example of running dash application in raspberry pie.
Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
useEffect,函數組件掛載和卸載時觸發
< li> dot style list style type
Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
AcWing——第55场周赛
Codeforces round 797 (Div. 3) no f
QT按钮点击切换QLineEdit焦点(含代码)
Advancedinstaller installation package custom action open file
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
It is forbidden to trigger onchange in antd upload beforeupload
Sanic异步框架真的这么强吗?实践中找真理
Input can only input numbers, limited input
useEffect,函数组件挂载和卸载时触发
Advancedinstaller安装包自定义操作打开文件