通过阈值方法调整图片清晰程度
1、import cv2 as cv
import numpy as np
font = cv.FONT_HERSHEY_SIMPLEX
image = cv.imread("c:\\book.png")
cv.imshow('image', image)
加载图片

2、retval, thresholdImagre = cv.threshold(image, 100, 255, cv.THRESH_BINARY)
imgfont = cv.putText(thresholdImagre, 'thresholdImagre: 100,255', (100, 100), font, 1.2, (255, 255, 255), 2)
cv.imshow('thresholdImagre', thresholdImagre)
对彩色源图进行100-255阈值化

3、gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)retval1, threshold = cv.threshold(gray, 100, 255, cv.THRESH_BINARY)imgfont = cv.putText(threshold, 'threshold: 100,255', (100, 100), font, 1.2, (255, 255, 255), 2)cv.imshow('threshold', threshold)
转化成灰度后二值化处理
和上图比较:
图片都变清晰但是边缘存在彩色阴影或者黑白阴影

4、adaptiveThresholdMean = cv.adaptiveThreshold(gray,255,cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,13,9)
imgfont = cv.putText(adaptiveThresholdMean, 'adaptiveThresholdMean: 13,9', (100, 100), font, 1.2, (255, 255, 255), 2)
cv.imshow('adaptiveThresholdMean', adaptiveThresholdMean)
采用自适应平均大法。
二值化,窗口大小选13,常数c选择9

5、adaptiveThresholdGaua = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 13, 9)
imgfont = cv.putText(adaptiveThresholdGaua, 'adaptiveThresholdGaua: 13,9', (100, 100), font, 1.2, (255, 255, 255), 2)
cv.imshow('adaptiveThresholdGaua', adaptiveThresholdGaua)
采用自适应高斯大法。
二值化,窗口大小选13,常数c选择9

6、小结:
采用adaptiveThreshold函数能够明显改善清晰度,并且边角也比较清晰。
注意:但是窗口和常数的选择会影响效果。
比如 窗口和常数 13, 1 效果马上变坏。
