1 篇文章 1 订阅

# 编译环境

## 前提

import cv2
from pylab import *

def MeanFilter(Imge,dim):       #Image为待处理图像，dim为滤波器的大小dim*dim
im=array(Imge)
sigema=0
for i in range(int(dim/2), im.shape[0] - int(dim/2)):
for j in range(int(dim/2), im.shape[1] - int(dim/2)):
for a in range(-int(dim/2), -int(dim/2)+dim):
for b in range(-int(dim/2), -int(dim/2)+dim):
sigema = sigema + img[i + a, j + b]
im[i, j] = sigema / (dim*dim)
sigema = 0
return im

df MedianFilter(Imge,dim):       #Image为待处理图像，dim为滤波器的大小dim*dim
im=array(Imge)
sigema=[]
for i in range(int(dim/2), im.shape[0] - int(dim/2)):
for j in range(int(dim/2), im.shape[1] - int(dim/2)):
for a in range(-int(dim/2), -int(dim/2)+dim):
for b in range(-int(dim/2), -int(dim/2)+dim):
sigema.append(img[i + a, j + b])
sigema.sort()
im[i, j] = sigema[int(dim*dim/2)]
sigema = []
return im
im3=MeanFilter(img,3)
im5=MeanFilter(img,5)
im7=MeanFilter(img,7)
cv2.imshow('junzhilvbo 3*3',im3)
cv2.imshow('junzhilvbo 5*5',im5)
cv2.imshow('junzhilvbo 7*7',im7)
cv2.imshow('Origin',img)
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
from pylab import *

def MedianFilter(Imge,dim):       #Image为待处理图像，dim为滤波器的大小dim*dim
im=array(Imge)
sigema=[]
for i in range(int(dim/2), im.shape[0] - int(dim/2)):
for j in range(int(dim/2), im.shape[1] - int(dim/2)):
for a in range(-int(dim/2), -int(dim/2)+dim):
for b in range(-int(dim/2), -int(dim/2)+dim):
sigema.append(img[i + a, j + b])
sigema.sort()
im[i, j] = sigema[int(dim*dim/2)]
sigema = []
return im
im3=MedianFilter(img,3)
im5=MedianFilter(img,5)
im7=MedianFilter(img,7)
cv2.imshow('zhongzhilvbo 3*3',im3)
cv2.imshow('zhongzhilvbo 5*5',im5)
cv2.imshow('zhongzhilvbo 7*7',im7)
cv2.imshow('Origin',img)
cv2.waitKey()
cv2.destroyAllWindows()

• 1
点赞
• 0
评论
• 10
收藏
• 一键三连
• 扫一扫，分享海报

06-02 243
11-05 3617
12-21 3332
07-16 1792
10-24 1221
12-01 549
06-11 7136
09-19 1万+