当前位置:网站首页>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()

边栏推荐
- Spark independent cluster dynamic online and offline worker node
- Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
- Market trend report, technical innovation and market forecast of double-sided foam tape in China
- Li Kou - 298th weekly match
- 生成随机密码/验证码
- 力扣leetcode第 280 场周赛
- (POJ - 3186) treatments for the cows (interval DP)
- Codeforces Round #798 (Div. 2)A~D
- Chapter 6 datanode
- Codeforces Round #797 (Div. 3)无F
猜你喜欢

我在字节跳动「修电影」

第6章 DataNode

解决Intel12代酷睿CPU【小核载满,大核围观】的问题(WIN11)

Simply try the new amp model of deepfacelab (deepfake)

Codeforces Round #799 (Div. 4)A~H

Chapter 5 yarn resource scheduler

Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog

本地可视化工具连接阿里云centOS服务器的redis

QT implementation window gradually disappears qpropertyanimation+ progress bar

新手必会的静态站点生成器——Gridsome
随机推荐
第5章 NameNode和SecondaryNameNode
Market trend report, technical innovation and market forecast of China's desktop capacitance meter
< li> dot style list style type
QT implementation fillet window
Tree of life (tree DP)
Native JS realizes the functions of all selection and inverse selection -- Feng Hao's blog
ffmpeg命令行使用
China double brightening film (dbef) market trend report, technical dynamic innovation and market forecast
Codeforces Round #803 (Div. 2)A~C
腾讯面试算法题
(lightoj - 1370) Bi shoe and phi shoe (Euler function tabulation)
(lightoj - 1369) answering queries (thinking)
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
300th weekly match - leetcode
Chapter 6 datanode
Chapter 2 shell operation of hfds
Acwing: the 56th weekly match
业务系统从Oracle迁移到openGauss数据库的简单记录
Classic application of stack -- bracket matching problem
Market trend report, technical innovation and market forecast of double-sided foam tape in China