You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
919 B

# 导入numpy包
import numpy as np
# 导入opencv包
import cv2
import math
def mf(image_path):
# 使用opencv读取图片
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# 待输出的图片
output = np.zeros(image.shape, np.uint8)
# 遍历图像,进行均值滤波
for i in range(image.shape[0]):
for j in range(image.shape[1]):
# 计算均值,完成对图片src的几何均值滤波
ji = 1.0
# 遍历滤波器内的像素值
total = 1
for x in range(-1, 2):
if i + x >= 0 and i + x < image.shape[0]:
total *= image[i + x, j]
# 计算滤波后的像素值
output[i, j] = np.uint8(np.power(total, 1 / 3))
# 滤波器的大小为1*3
cv2.imshow('result', output)
cv2.waitKey(0)
cv2.destroyAllWindows()