我正在尝试为扫描的文档制作一个神奇的颜色过滤器,但没有得到所需的输出。在某些文档中,某些文档中的文本会失真,图像颜色会丢失。在某些文档中,文本变得太厚。我正在使用高斯的拉普拉斯算子进行边缘增强,然后进行阈值处理,最后模糊图像以获得自然的外观。
import cv2
import numpy as np
img = cv2.imread('example_output/sample16.jpeg')
original = img.copy()
kernel_sharpen_3 = np.array([[-1, -1, -1, -1, -1],
[-1, 2, 2, 2, -1],
[-1, 2, 8, 2, -1],
[-1, 2, 2, 2, -1],
[-1, -1, -1, -1, -1]]) / 8
img = cv2.filter2D(img, -1, kernel_sharpen_3)
ret, threshold = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY)
blur = cv2.GaussianBlur(threshold, (5, 5), 0)
stack_horizontal = np.concatenate((original, img), axis=1)
stack_horizontal2 = np.concatenate((threshold, blur), axis=1)
stack_vertical = np.concatenate((stack_horizontal, stack_horizontal2), axis=0)
cv2.imshow('Images', cv2.resize(stack_vertical, (700, 1000)))
cv2.imwrite("magic.jpg", threshold)
cv2.waitKey()
cv2.destroyAllWindows()
输入图像:

我的结果:

期望的输出:
