Jos*_*ang 3 python opencv image-processing computer-vision binary-image
在图像上使用 open CV 中的阈值函数来获取二值图像,通过 Otsu 的阈值处理,我得到的图像由于图像部分的光照条件不同而具有白点
或者使用自适应阈值来修复光照条件,它无法准确地表示 Otsu 实际可以表示的铅笔填充的气泡。
如何获得所代表的填充气泡和没有补丁的固定照明条件?这是原始图像

这是我的代码
#binary image conversion
thresh2 = cv2.adaptiveThreshold(papergray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 21, 13)
thresh = cv2.threshold(papergray, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow("Binary", thresh) #Otsu's
cv2.imshow("Adpative",thresh2)
Run Code Online (Sandbox Code Playgroud)
另一种方法是应用形态学闭合,这将删除所有绘图,从而产生照明水平的估计。将图像除以照明级别即可得到经过照明校正的纸张图像:
在此图像中,我们可以轻松应用全局阈值:
我使用了以下代码:
import diplib as dip
img = dip.ImageRead('tlCw6.jpg')(1)
corrected = img / dip.Closing(img, dip.SE(40, 'rectangular'))
out = dip.Threshold(corrected, method='triangle')[0]
Run Code Online (Sandbox Code Playgroud)
小智 5
这可以通过以下方式完成cv2.ADAPTIVE_THRESH_MEAN_C:
import cv2
img = cv2.imread("omr.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 31, 10)
cv2.imshow("Mean Adaptive Thresholding", thresh)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
741 次 |
| 最近记录: |