当前位置:网站首页>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独立集群Worker和Executor的概念
- (POJ - 3186) treatments for the cows (interval DP)
- Codeforces Round #800 (Div. 2)AC
- 【锟斤拷】的故事:谈谈汉字编码和常用字符集
- Remove the border when input is focused
- 去掉input聚焦时的边框
- useEffect,函數組件掛載和卸載時觸發
- VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
- 第五章 Yarn资源调度器
- China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
猜你喜欢

图像处理一百题(11-20)

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

Cmake Express

(lightoj - 1323) billiard balls (thinking)

简单尝试DeepFaceLab(DeepFake)的新AMP模型

< li> dot style list style type

解决Intel12代酷睿CPU单线程调度问题(二)

antd upload beforeUpload中禁止触发onchange

我在字节跳动「修电影」

QT style settings of qcobobox controls (rounded corners, drop-down boxes, up expansion, editable, internal layout, etc.)
随机推荐
Market trend report, technical innovation and market forecast of China's desktop capacitance meter
Basic principles of video compression coding and audio compression coding
使用jq实现全选 反选 和全不选-冯浩的博客
MariaDB的安装与配置
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
字节跳动新程序员成长秘诀:那些闪闪发光的宝藏mentor们
拉取分支失败,fatal: ‘origin/xxx‘ is not a commit and a branch ‘xxx‘ cannot be created from it
Oneforall installation and use
原生js实现全选和反选的功能 --冯浩的博客
指定格式时间,月份天数前补零
Market trend report, technological innovation and market forecast of China's double sided flexible printed circuit board (FPC)
第6章 DataNode
Spark独立集群动态上线下线Worker节点
Problem - 1646C. Factorials and Powers of Two - Codeforces
提交Spark应用的若干问题记录(sparklauncher with cluster deploy mode)
Kubernetes cluster deployment
Hbuilder x format shortcut key settings
Click QT button to switch qlineedit focus (including code)
视频压缩编码和音频压缩编码基本原理
Log statistics (double pointer)