当前位置:网站首页>图像处理一百题(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()
边栏推荐
- Study notes of Tutu - process
- 生成随机密码/验证码
- China double brightening film (dbef) market trend report, technical dynamic innovation and market forecast
- (POJ - 3579) median (two points)
- Is the sanic asynchronous framework really so strong? Find truth in practice
- AcWing——第55场周赛
- Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
- 第 300 场周赛 - 力扣(LeetCode)
- Oneforall installation and use
- (lightoj - 1349) Aladdin and the optimal invitation (greed)
猜你喜欢
Codeforces Round #799 (Div. 4)A~H
Read and save zarr files
新手必会的静态站点生成器——Gridsome
OneForAll安装使用
Sword finger offer II 019 Delete at most one character to get a palindrome
1689. Ten - the minimum number of binary numbers
Pull branch failed, fatal: 'origin/xxx' is not a commit and a branch 'xxx' cannot be created from it
Codeforces Round #799 (Div. 4)A~H
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
Some problems encountered in installing pytorch in windows11 CONDA
随机推荐
生成随机密码/验证码
第 300 场周赛 - 力扣(LeetCode)
力扣:第81场双周赛
Discussion on QWidget code setting style sheet
Bidirectional linked list - all operations
业务系统兼容数据库Oracle/PostgreSQL(openGauss)/MySQL的琐事
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Installation and configuration of MariaDB
Flask框架配置loguru日志庫
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
Codeforces round 797 (Div. 3) no f
Acwing - game 55 of the week
QT实现圆角窗口
Hbuilder X格式化快捷键设置
(lightoj - 1323) billiard balls (thinking)
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
Market trend report, technological innovation and market forecast of double door and multi door refrigerators in China
Market trend report, technical innovation and market forecast of tabletop dishwashers in China
605. Planting flowers
(POJ - 3685) matrix (two sets and two parts)