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

边栏推荐
- sqlDeveloper工具快速入门
- First knowledge of opencv4.x --- image perspective transformation
- 14. Bridge based active domain adaptation for aspect term extraction reading notes
- UE4 smart pointer and weak pointer
- 如何评价测试质量?
- Sqldeveloper tools quick start
- Error reported by Nacos enabled client
- "Baget" takes you one minute to build your own private nuget server
- Instructions for various interfaces of hand-held vibrating wire collector vh03
- Unity学习笔记–无限地图
猜你喜欢

Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process

Plato farm is expected to further expand its ecosystem through elephant swap

VP视频结构化框架

10 schemes to ensure interface data security

Iscc2021 lock problem solution

Win11 running virtual machine crashed? Solution to crash of VMware virtual machine running in win11

Leetcode36 effective Sudoku
![[dry goods] data structure and algorithm principle behind MySQL index](/img/80/d5ab431cd5112b1637ee07d5b59afa.png)
[dry goods] data structure and algorithm principle behind MySQL index

4 kinds of round head arrangement styles overlay styles

C# 常用功能整合
随机推荐
键盘快捷键操作电脑(自己遇到不会的)
As the "first city" in Central China, Changsha's "talent attraction" has changed from competition to leadership
Multithreading - thread pool
WPF 常用功能整合
VP视频结构化框架
Leetcode1170- compare the occurrence frequency of the minimum letter of the string (the corresponding occurrence frequency of each string minimum element in the map set storage array)
Install dexdump on win10 and remove the shell
C # use shift > > and operation and & to judge whether the two binary numbers have changed
winscp传输文件和VNC连接问题
PyTorch的简单实现
[untitled]
Uni app from creation to operation to wechat developer tool
Seata的部署与微服务集成
C# Winfrom 常用功能整合
【整数规划】
14. Bridge based active domain adaptation for aspect term extraction reading notes
~6. CCF 2021-09-1 array derivation
Canvas mesh wave animation JS special effect
【1.2.投资的收益和风险】
[ostep] 03 virtualized CPU - restricted direct execution mechanism