当前位置:网站首页>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 .
边栏推荐
- C WinForm panel custom picture and text
- 50. Pow(x, n)-快速幂
- 1464. maximum product of two elements in an array
- navicat定时任务无效
- CAN总线工作状况和信号质量“体检”
- c#搭建ftp服务器并实现文件上传和下载
- 【Unexpected token o in JSON at position 1出错原因及解决方法】
- 挖掘微生物暗物质——新思路
- 27. remove elements
- Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
猜你喜欢

How to select lead-free and lead-free tin spraying for PCB? 2021-11-16

网络模型——OSI模型与TCP/IP模型

Matlab代码格式一键美化神器

取消word文档中某些页面的页眉

产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具

使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障

socket问题记录

传统的IO存在什么问题?为什么引入零拷贝的?

Neural network and deep learning-3-simple example of machine learning pytorch

将数据导入到MATLAB
随机推荐
NSIS silent installation vs2013 runtime
电子学:第014课——实验 15:防入侵报警器(第一部分)
Microsoft Office Word 远程命令执行漏洞(CVE-2022-30190)分析与利用
网络模型——OSI模型与TCP/IP模型
C WinForm panel custom picture and text
Analysis of kinsing dual platform mining family virus
洛谷P2839 [国家集训队]middle(二分 + 主席树 + 区间合并)
Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer
1742. 盒子中小球的最大数量
c#搭建ftp服务器并实现文件上传和下载
Share the process requirements for single-layer flexible circuit board
Ubuntu18下登录mysql 5.7设置root密码
Force deduction 76 questions, minimum covering string
Neural network and deep learning-3-simple example of machine learning pytorch
Machine learning notes linear regression of time series
黑点==白点(MST)
What are the problems with traditional IO? Why is zero copy introduced?
C control refresh
洛谷P1073 [NOIP2009 提高组] 最优贸易(分层图+最短路)
MySQL interview - the response of executing SQL is relatively slow, and the troubleshooting ideas.