您需要选择具有所需厚度的对象

2024-04-24 07:32:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的代码,它使用skimage threshold_minimum突出显示行。是的,这可能不是理想的方法。但是,在生成的图像中,我需要选择厚度小于某个像素值的线。也就是说,我希望通过指定3个像素的值,图像中的一些线条将被删除。我认为cv2.HoughLines是一个选项,但它只画直线

代码:

import matplotlib.pyplot as plt
import cv2
from skimage.filters import threshold_otsu, threshold_mean, threshold_minimum, try_all_threshold

# Load image
img = cv2.imread('C:\\temp\\map.png', 0)

thresh_min = threshold_minimum(img)
binary_min = img > thresh_min

fig, axes = plt.subplots(ncols=2, figsize=(8, 3))
ax = axes.ravel()

ax[0].imshow(img, cmap=plt.cm.gray)
ax[0].set_title('Original')

ax[1].imshow(binary_min, cmap=plt.cm.gray)
ax[1].set_title('Thresholded (min)')

plt.show()

结果图像:

enter image description here