当前位置:网站首页>图像处理一百题(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()

边栏推荐
- 875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
- 软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
- Spark独立集群动态上线下线Worker节点
- 力扣:第81场双周赛
- Bisphenol based CE Resin Industry Research Report - market status analysis and development prospect forecast
- Generate random password / verification code
- 日期加1天
- Codeforces Round #803 (Div. 2)A~C
- 409. Longest palindrome
- 浏览器打印边距,默认/无边距,占满1页A4
猜你喜欢

Codeforces Round #801 (Div. 2)A~C

Installation and configuration of MariaDB

Codeforces Round #802(Div. 2)A~D

Flask框架配置loguru日志库

It is forbidden to trigger onchange in antd upload beforeupload

pytorch提取骨架(可微)

(lightoj - 1323) billiard balls (thinking)

Raspberry pie 4B installation opencv3.4.0

去掉input聚焦时的边框

Codeforces Round #802(Div. 2)A~D
随机推荐
Candy delivery (Mathematics)
OneForAll安装使用
860. Lemonade change
Raspberry pie 4b64 bit system installation miniconda (it took a few days to finally solve it)
业务系统从Oracle迁移到openGauss数据库的简单记录
Summary of game theory
1529. Minimum number of suffix flips
Classic application of stack -- bracket matching problem
Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
pytorch提取骨架(可微)
Specify the format time, and fill in zero before the month and days
Codeforces Round #797 (Div. 3)无F
Tree of life (tree DP)
QT模拟鼠标事件,实现点击双击移动拖拽等
QT implementation window gradually disappears qpropertyanimation+ progress bar
Radar equipment (greedy)
Educational Codeforces Round 130 (Rated for Div. 2)A~C
AcWing:第56场周赛
Flag framework configures loguru logstore
Advancedinstaller installation package custom action open file