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)
去噪点(二维中值滤波)
于 2020-03-18 18:02:18 首次发布