<p>在Python/OpenCV中有一种方法可以做到这一点</p>
<ul>
<li>读取输入</li>
<li>增加对比度</li>
<li>将原始图像转换为灰度</li>
<li>自适应阈值</li>
<li>使用阈值图像使对比度增加的图像上的背景为白色</li>
<li>保存结果</li>
</ul>
<br/>
<p>输入:</p>
<p><a href="https://i.stack.imgur.com/73wYh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/73wYh.jpg" alt="enter image description here"/></a></p>
<pre><code>import cv2
import numpy as np
# read image
img = cv2.imread("math_diagram.jpg")
# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# do adaptive threshold on gray image
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 15)
# make background of input white where thresh is white
result = img.copy()
result[thresh==255] = (255,255,255)
# write results to disk
cv2.imwrite("math_diagram_threshold.jpg", thresh)
cv2.imwrite("math_diagram_processed.jpg", result)
# display it
cv2.imshow("THRESHOLD", thresh)
cv2.imshow("RESULT", result)
cv2.waitKey(0)
</code></pre>
<br/>
<p>阈值图像:</p>
<p><a href="https://i.stack.imgur.com/QSQ5p.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QSQ5p.jpg" alt="enter image description here"/></a></p>
<p>结果:</p>
<p><a href="https://i.stack.imgur.com/kB24B.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kB24B.jpg" alt="enter image description here"/></a></p>