<p>我刚刚遇到了另一个关于选择<strong>最佳</strong>阈值进行边缘检测的解决方案。我之前的回答是关于<strong>自适应阈值</strong>,你对此非常了解。在</p>
<p>所谓的<strong>最优</strong>是指根据灰度图像的<strong>中值</strong>值选择两个值(下限和上限)。下面的代码将向您展示如何完成此操作:</p>
<pre><code>v = np.median(gray_img)
sigma = 0.33
# apply optimal Canny edge detection using the computed median
lower_thresh = int(max(0, (1.0 - sigma) * v))
upper_thresh = int(min(255, (1.0 + sigma) * v))
edge_img = cv2.Canny(gray_img, lower_thresh, upper_thresh)
cv2.imshow('Edge_of_box',edge_img)
</code></pre>
<p><strong>0.33的</strong>西格玛值是数据科学领域中最理想的值。在</p>
<p><strong><em>插图:</em></strong>如果您观察到统计中的高斯曲线,则分布中会考虑曲线两侧0.33之间的值。假设这些点之外的任何值都是异常值。因为图像被认为是数据,所以这里也假设了这个概念。在</p>
<p>看看这个:</p>
<p><a href="https://i.stack.imgur.com/fpKax.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fpKax.jpg" alt="enter image description here"/></a></p>
<p>现在,你经常贴的第二个盒子:</p>
<p><a href="https://i.stack.imgur.com/j3iVm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j3iVm.jpg" alt="enter image description here"/></a></p>
<h2>你如何改善这一点?在</h2>
<p>我一直想试试下面的方法。试试看,一定要告诉我:</p>
<ul>
<li>首先尝试将<strong>中值</strong>替换为<strong>平均值</strong>,并观察
结果。在</li>
<li>更改<strong>sigma</strong>值并观察边缘检测如何变化。在</li>
<li>尝试对图像的一小部分执行上述技术。将图像分成小块,然后按你的方式处理。(我的意思是“<strong>局部边缘检测</strong>”)</li>
</ul>
<p>也许有更好的方法来发现我还没有遇到的。但这是一个伟大的和<strong>有趣的开始方式。在</p>