去噪点(二维中值滤波)

import cv2
import numpy as np
import scipy.signal as signal
from PIL import Image

input_images = np.zeros((300, 300))
filename = r"E:\doublelayer-plate-rec\originpic\2.png"
print(filename)
# img = Image.open(filename).resize((300, 300)).convert('L')
img = Image.open(filename).resize((300, 300)).convert('L')
width = img.size[0]
height = img.size[1]

data = signal.medfilt2d(np.array(img), kernel_size=5)  # 二维中值滤波
for h in range(0, height):
    for w in range(0, width):
        if data[w][h] < 128:
            input_images[w, h] = 0
        else:
            input_images[w, h] = 1
cv2.imshow("test3333", input_images)

tmp = cv2.resize(input_images, (332, 178))
tmp = tmp * 255  # 将图片的取值范围改成(0~255)#skimg保存数据时需要将浮点型转换成整型
tmp = tmp.astype(np.uint8)
cv2.imwrite(r"E:\doublelayer-plate-rec\originpic\1.png", tmp)
cv2.waitKey(0)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值