当前位置:网站首页>median filter
median filter
2022-07-26 14:42:00 【Bring salt to rice】
Median filter belongs to nonlinear filter , Median filtering is the process of solving the median of the whole image .
import cv2 as cv
import matplotlib.pyplot as plt
import math
import numpy as np
plt.rcParams['font.sans-serif'] =['SimHei'] # Show Chinese tags
def get_median(data):
data.sort()
half = len(data) // 2
return data[half]
# Calculate the median filter of gray image
def my_median_blur_gray(image, size):
data = []
sizepart = int(size/2)
for i in range(image.shape[0]):
for j in range(image.shape[1]):
for ii in range(size):
for jj in range(size):
# First, judge whether it is out of range , You can also zero fill the image in advance
if (i+ii-sizepart)<0 or (i+ii-sizepart)>=image.shape[0]:
pass
elif (j+jj-sizepart)<0 or (j+jj-sizepart)>=image.shape[1]:
pass
else:
data.append(image[i+ii-sizepart][j+jj-sizepart])
# Take the median in each region
image[i][j] = int(get_median(data))
data=[]
return image
def my_median_blur_RGB(image, size):
(b ,r, g) = cv.split(image)
blur_b = my_median_blur_gray(b, size)
blur_r = my_median_blur_gray(r, size)
blur_g = my_median_blur_gray(g, size)
result = cv.merge((blur_b, blur_r, blur_g))
return result
if __name__ == '__main__':
image_test1 = cv.imread('apic27858.jpg')
# Call custom functions
my_image_blur_median = my_median_blur_RGB(image_test1, 5)
# Call library function
computer_image_blur_median = cv.medianBlur(image_test1, 5)
fig = plt.figure()
fig.add_subplot(131)
plt.title(' Original picture ')
plt.imshow(image_test1)
fig.add_subplot(132)
plt.title(' Custom function filtering ')
plt.imshow(my_image_blur_median)
fig.add_subplot(133)
plt.title(' Library function filtering ')
plt.imshow(computer_image_blur_median)
plt.show()

边栏推荐
- 基于CAS的SSO单点登录环境搭建
- URL的使用下载资源
- [untitled]
- Wechat applet - "do you really understand the use of applet components?
- C# 常用功能整合
- Create root permission virtual environment
- Embedded development: skills of debugging embedded software
- 【使用工具条绘图】
- [ostep] 04 virtualized CPU - process scheduling strategy
- Leetcode36 effective Sudoku
猜你喜欢
![[ostep] 04 virtualized CPU - process scheduling strategy](/img/42/7ffb9745ef21a8db35861119dd70bf.png)
[ostep] 04 virtualized CPU - process scheduling strategy

Classic line style login interface

C nanui related function integration

win10安装Dexdump并脱壳

JS wave animation effect menu style

Keyboard shortcut to operate the computer (I won't encounter it myself)

Mlx90640 infrared thermal imager temperature sensor module development notes (6)

【使用工具条绘图】

RPN:Region Proposal Networks (区域候选网络)

图神经网络Core数据集介绍
随机推荐
中部“第一城”,长沙“人才引力”从争先到领先
『云原生』KubeSphere可插拔组件之DevOps系统
Keyboard shortcut to operate the computer (I won't encounter it myself)
TransC知识表示模型
多线程——线程池
31. Opinion-based Relational Pivoting forCross-domain Aspect Term Extraction 阅读笔记
sp导出贴图到maya
【使用工具条绘图】
【常微分方程求解及绘图之求解小船行走轨迹】
4 kinds of round head arrangement styles overlay styles
My creation Anniversary - from the heart
【2022国赛模拟】白楼剑——SAM、回滚莫队、二次离线
Instructions for various interfaces of hand-held vibrating wire collector vh03
Stacked noise reducing auto encoder (sdae)
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
Image-Level 弱监督图像语义分割汇总简析
【1.2.投资的收益和风险】
Leetcode36 effective Sudoku
C common function integration
VP视频结构化框架