<p>这个答案是基于这样一个假设:亮点总是以垂直线的形式出现。在这个样本图像上进行了测试,结果是相当好的,但是在其他类似的图片上肯定需要更多的测试。也就是说,我建议你试着找出阈值图像上的白点,这就是“斑点”,就像你已经在倒数第二张图片中发布的一样。如果愿意,可以通过转置函数<code>np.findnonzero(thresholded_image)</code>来获得位置或坐标。然后迭代列表,将原始图像的所有像素替换为与iter坐标相同的像素(x-1)。结果是:</p>
<pre><code>import cv2
import numpy as np
img = cv2.imread('remove.png')
height,width = img.shape[:2]
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray,225,255,cv2.THRESH_BINARY)
cds = np.transpose(np.nonzero(thresh))
for i in cds:
if i[1] == 0:
pass
else:
img[i[0],i[1]] = img[i[0], i[1]-1]
cv2.imshow("res", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code></pre>
<p>原始图像:</p>
<p><a href="https://i.stack.imgur.com/RlHf2.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RlHf2.gif" alt="enter image description here"/></a></p>
<p>阴影图像:</p>
<p><a href="https://i.stack.imgur.com/ZI94m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZI94m.png" alt="enter image description here"/></a></p>
<p>结果图像:</p>
<p><a href="https://i.stack.imgur.com/VimEO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VimEO.png" alt="enter image description here"/></a></p>
<p>希望它能给你一点帮助或者给你一个有用的新想法。干杯!在</p>
<p>编辑:</p>
<p>或者一种更好的方法:
使用<code>cv2.inpaint()</code>函数,而不是遍历每个像素:</p>
^{pr2}$
<p>结果:</p>
<p><a href="https://i.stack.imgur.com/TkQLJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TkQLJ.png" alt="enter image description here"/></a></p>