通过阈值方法调整图片清晰程度

2024-10-21 14:19:37

1、import cv2 as cvimport numpy as npfont = cv.FONT_HERSHEY_SIMPLEXimage = cv.imread("c:\\book.png")cv.imshow('image', image)加载图片

通过阈值方法调整图片清晰程度

3、gray = c箪滹埘麽v.cvtColor(image, cv.COLOR_BGR2GRAY)retval1, threshold = cv.thr髫潋啜缅eshold(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)转化成灰度后二值化处理和上图比较:图片都变清晰但是边缘存在彩色阴影或者黑白阴影

通过阈值方法调整图片清晰程度

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

通过阈值方法调整图片清晰程度
猜你喜欢