python切比雪夫滤波器_使用python的平均滤波器

我是python的新手,尝试在图像上应用平均过滤器作为理解平均概念的方法summing up the neighboring elements including itself and divide it by number of elements

technique

但问题是得到的是暗图像,而不是模糊图像的结果image = cv2.imread('./images/hip-salt.jpg', 0);

width = image.shape[1]

height = image.shape[0]

result = np.zeros((image.shape[0], image.shape[1]), int)

def meanFilter():

for row in range(height):

for col in range(width):

currentElement=0; left=0; right=0; top=0; bottom=0; topLeft=0;

topRight=0; bottomLeft=0; bottomRight=0;

counter = 1

currentElement = image[row][col]

if not col-1 < 0:

left = image[row][col-1]

counter +=1

if not col+1 > width-1:

right = image[row][col+1]

counter +=1

if not row-1 < 0:

top = image[row-1][col]

counter +=1

if not row+1 > height-1:

bottom = image[row+1][col]

counter +=1

if not row-1 < 0 and not col-1 < 0:

topLeft = image[row-1][col-1]

counter +=1

if not row-1 < 0 and not col+1 > width-1:

topRight = image[row-1][col+1]

counter +=1

if not row+1 > height-1 and not col-1 < 0:

bottomLeft = image[row+1][col-1]

counter +=1

if not row+1 > height-1 and not col+1 > width-1:

bottomRight = image[row+1][col+1]

counter +=1

total = int(currentElement)+int(left)+int(right)+int(top)+int(bottom)+int(topLeft)+int(topRight)+int(bottomLeft)+int(bottomRight)

avg = total/counter

result[row][col] = avg

meanFilter();

cv2.imshow('Averaging Filter', result);

cv2.waitKey(0)

cv2.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值