当前位置:网站首页>One hundred questions of image processing (11-20)
One hundred questions of image processing (11-20)
2022-07-06 16:42:00 【Dog egg L】
Question 11 : Mean filter
Use 3*3 Let's use the average filter of !
The output of the smooth linear spatial filter is a simple average of the pixels contained in the neighborhood of the filter template , Mean filter . The mean filter is also a low-pass filter , Mean filter is easy to understand , That is, assign the average value in the neighborhood to the central element .
Mean filter is used to reduce noise , The main application of mean filter is to remove irrelevant details in the image , Uncorrelation refers to the small pixel area compared with the filter template . Blur the picture to get a rough description of the object of interest , So the grayscale of those smaller objects will be mixed with the background , Larger objects become like spots and are easy to detect . The size of the template is determined by the size of the objects that will blend into the background .
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()
Original image
After processing the image
Question 12 :Motion Filter
Motion Filter Take the average value of pixels in the diagonal direction , Define as follows :
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 797 (Div. 3) no f
- Log statistics (double pointer)
- (lightoj - 1236) pairs forming LCM (prime unique decomposition theorem)
- It is forbidden to trigger onchange in antd upload beforeupload
- Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
- Spark独立集群动态上线下线Worker节点
- Tert butyl hydroquinone (TBHQ) Industry Research Report - market status analysis and development prospect forecast
- <li>圆点样式 list-style-type
- 第五章 Yarn资源调度器
- Market trend report, technical innovation and market forecast of China's desktop capacitance meter
猜你喜欢
解决Intel12代酷睿CPU单线程调度问题(二)
Hbuilder X格式化快捷键设置
Install Jupiter notebook under Anaconda
顺丰科技智慧物流校园技术挑战赛(无t4)
Browser print margin, default / borderless, full 1 page A4
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Audio and video development interview questions
软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
Local visualization tools are connected to redis of Alibaba cloud CentOS server
Kubernetes集群部署
随机推荐
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
Specify the format time, and fill in zero before the month and days
业务系统从Oracle迁移到openGauss数据库的简单记录
Market trend report, technological innovation and market forecast of China's double sided flexible printed circuit board (FPC)
去掉input聚焦时的边框
Market trend report, technological innovation and market forecast of desktop electric tools in China
Solve the problem of intel12 generation core CPU [small core full, large core onlookers] (win11)
Chapter 6 rebalance details
Spark独立集群Worker和Executor的概念
useEffect,函数组件挂载和卸载时触发
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
Input can only input numbers, limited input
Codeforces - 1526C1&&C2 - Potions
Market trend report, technical innovation and market forecast of tabletop dishwashers in China
(lightoj - 1236) pairs forming LCM (prime unique decomposition theorem)
Submit several problem records of spark application (sparklauncher with cluster deploy mode)
Codeforces Round #802(Div. 2)A~D
Acwing: Game 58 of the week
Sublime text code formatting operation
第一章 MapReduce概述