当前位置:网站首页>Opencv minimum filtering (not limited to images)
Opencv minimum filtering (not limited to images)
2022-06-25 07:56:00 【Coding leaves】
opencv There are many filter functions in , Such as median filtering , But there is no maximum and minimum filtering . This article will introduce how to use python numpy Realize the minimum filtering function , It can be said that there is no need to resort to opencv That is to say .
1 Defined function minBlur
The function that defines the minimum filter is minBlur, contain 3 Parameters , They are as follows :
(1)image: The input image ,array type .
(2)kernel: Minimum range ,tuple type , The first element represents x Range of minimum value for direction , The second element represents y Range of minimum value for direction .
(3)limit: Elements that require minimum filtering ,tuple type , Such as (a,b) Indicates that the range of pixel values is [a, b] The minimum value filtering is performed only for pixels of .
This function achieves the following compatibility :
(1) Suitable for grayscale pictures or RGB picture .
(2) Not limited to arrays of images ,array.
(3) Suitable for any number of channels .
2 Reference procedure
import numpy as np
def minBlur(image, kernel=(3, 3), limit=(0, 255)):
"""
Parameters
----------
image : array, Input matrix or array .
kernel : tuple or list, optional
Respectively x、y Range of minimum value in direction . The default is (3, 3).
limit : tuple or list, optional
Specifies the pixel range for minimum filtering . The default is (0, 255).
Returns
-------
image_c : array, Processed matrix or array .
"""
image_c = image.copy()
if len(image_c.shape) == 2:
image_c = image_c[:, :, np.newaxis]
h, w, c = image_c.shape
image_c1 = image_c.copy()
for i in range(h):
for j in range(w):
x1 = max(j-kernel[0]//2, 0)
x2 = min(x1 + kernel[0], w)
y1 = max(i-kernel[1]//2, 0)
y2 = min(y1 + kernel[1], h)
for k in range(c):
if image_c[i, j, k] >= limit[0] and image_c[i, j, k] <= limit[1]:
sub_img = image_c1[y1:y2, x1:x2, k]
image_c[i, j, k] = np.min(sub_img)
if len(image.shape) == 2:
image_c = image_c.reshape(h, w)
return image_c
if __name__ == '__main__':
np.random.seed(1)
x = np.random.randint(0, 256, (10, 10))
x[x>150] = 255
y = minBlur(x)
print('x:\n', x)
print('y:\n', y)
3 test result
More 3D 、 Please pay attention to two-dimensional perception algorithm and financial quantitative analysis algorithm “ Lele perception school ” WeChat official account , And will continue to update .
边栏推荐
- [deep learning lightweight backbone] 2022 edgevits CVPR
- Atlassian Confluence 远程代码执行漏洞(CVE-2022-26134漏洞分析与防护
- PCB board design - automatic layout 2021-10-15
- Knowledge sharing 𞓜 conventional laminated structure of six layer PCB
- c#磁盘驱动器及文件夹还有文件类的操作
- Importer des données dans MATLAB
- 【Unexpected token o in JSON at position 1出错原因及解决方法】
- Linux上oracle和mysql的启动,关闭,重启
- 微信小程序开通客服消息功能开发
- Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
猜你喜欢
使用Adobe Acrobat Pro调整PDF页面为统一大小
Technology blog | how to communicate using SSE
【深度学习 轻量型backbone】2022 EdgeViTs CVPR
Pcb|about FPC reinforcement type
电子学:第014课——实验 15:防入侵报警器(第一部分)
电子学:第012课——实验 13:烧烤 LED
50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool
Six causes of PCB disconnection 2021-10-20
飞机引气系统的建模与故障仿真
What are the problems with traditional IO? Why is zero copy introduced?
随机推荐
Basic use of ActiveMQ in Message Oriented Middleware
php数组函数大全
Advantages and differences of three kinds of vias in PCB 2021-10-27
c#中设置lable控件的TextAlign属性控制文字居中的方法
Buckle 78: subset
三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试
用函数的递归来解决几道有趣的题
环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用
Kinsing双平台挖矿家族病毒分析
bat启动.NET Core
OAuth 2.0 one click login
[deep learning lightweight backbone] 2022 edgevits CVPR
2265. number of nodes with statistical value equal to the average value of subtree
MySQL simple permission management
神经网络与深度学习-3- 机器学习简单示例-PyTorch
@Resource和@Autowired注解的不同,为什么推荐@Resource?
NSIS silent installation vs2013 runtime
php入门基础记录
Usememo simulation usecallback
力扣78:子集