python - 使用输入的种子点过滤双阈值图像
问题描述
我已将多边形内的种子点标记为该多边形的双重阈值。在阈值图像取决于我标记的种子点之后,我想删除其余的连接组件。根据裁剪的图像,我有种子点的坐标。我想删除其余不需要的标记组件以设置为零并仅显示必要的图像片段。想象中心坐标为(x=37,y=40)。
使用种子点1提取的图像
提取图像的双阈值图像2
以下是从提取的图像中获取连接组件的代码。
def dual_threshold_method(crop_img):
mean, meanStd = cv2.meanStdDev(crop_img)
w = 2.0
lower_Threshold = mean - (w * meanStd) + 90
upper_Threshold = mean + (w * meanStd) + 90
ret1, img1 = cv2.threshold(crop_img, int(lower_Threshold), 255, cv2.THRESH_BINARY)
ret2, img2 = cv2.threshold(crop_img, int(upper_Threshold), 255, cv2.THRESH_BINARY)
dual_threshold_img = img1 - img2
retval, labels = cv2.connectedComponents(dual_threshold_img)
cv2.imshow('Dual_Threshold_Image', dual_threshold_img)
return labels, retval
https://drive.google.com/drive/folders/1UbXkYyCiMqVRXhn_KuSaKRHDUtQWhdnl?usp=sharing
以上链接包含双阈值图像和种子点标记图像
预期结果将与下图相同
https://drive.google.com/open?id=14zaQWz9C3qRNN-niM4LI1-iCenk7QIMN
解决方案
通过使用中心坐标像素强度过滤并添加扩张和侵蚀来解决这个问题。
pixel_value = labels[cropped_image_center_coordinates[0][0],cropped_image_center_coordinates[0][1]]
mask = np.array(labels, dtype=np.uint8)
mask[labels == pixel_value] = 255
kernel = np.ones((5, 5), np.uint8)
dilation = cv2.dilate(mask, kernel, iterations=1)
erosion = cv2.erode(dilation, kernel, iterations=1)
cv2.imshow('component', erosion)enter code here
推荐阅读
- aws-cdk - 带有 waitForTaskToken 的 Aws StepFunction 路径
- excel - 在 Excel 中基于组对数据进行排序
- django - Elastic Apm python代理连接问题
- ios - 在选择时关闭作为 UITextField 输入视图的 UIPickerView
- c# - .NET Core SDK - 多个文件夹来解析 SDK
- django - 为什么谷歌应用引擎柔性环境django出现502错误?
- cypress - Cypress-Xpath :: 使用 docker compose 文件运行时出错
- c# - C# 将动态属性添加到 PropertyInfo
- regex - 正则表达式 - 在另一个子字符串匹配之后搜索不包含两个子字符串中的任何一个的文本
- python - 我应该使用什么策略来定期从特定文件夹中提取信息