You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何清理道路骨架细化结果中过近的Harris角点(Julia实现)

解决Harris角点检测中近邻角点的过滤问题

核心思路

要处理间距过近的角点,核心是先提取所有角点的坐标,基于设定的距离阈值筛选出需要保留的角点,将剩余过近的角点从角点集合中移除(设为白色)。具体步骤:

  • 提取所有角点的笛卡尔坐标
  • 计算点间欧氏距离,标记过近的冗余点
  • 仅保留每个近邻点簇的一个代表点,其余还原为白色背景

修改后的代码实现

using Images
using LinearAlgebra

# 1. 骨架提取与初始角点检测
t = thinning(road_image)
detection_method = harris
corners = imcorner(t, Percentile(99.5); method=detection_method)

# 2. 提取所有角点的坐标
corner_coords = findall(corners)
# 设置距离阈值(根据图像尺寸调整,示例设为5像素)
distance_threshold = 5

# 3. 标记需要保留的角点
keep_corner = trues(length(corner_coords))
for i in 1:length(corner_coords)
    if keep_corner[i]  # 仅处理未被标记为移除的点
        for j in (i+1):length(corner_coords)
            # 计算两点间的欧氏距离
            dist = norm(Tuple(corner_coords[i]) .- Tuple(corner_coords[j]))
            if dist < distance_threshold
                keep_corner[j] = false  # 标记为冗余点
            end
        end
    end
end

# 4. 筛选出最终保留的角点
filtered_corner_coords = corner_coords[keep_corner]

# 5. 生成可视化图像:先还原所有原角点为白色,再标记保留的角点为红色
img_labels = RGB{N0f8}.(t)
img_labels[corner_coords] .= RGB(1.0, 1.0, 1.0)
img_labels[filtered_corner_coords] .= RGB(1.0, 0.0, 0.0)

关键说明

  • 阈值调整:distance_threshold的取值需结合图像分辨率和角点密集度调整,分辨率高则适当增大阈值。
  • 效率优化:若角点数量极大,可改用KD-Tree等高效近邻搜索算法替代双重循环,提升处理速度。
  • 替代方案:也可对初始角点图corners执行形态学开运算(imopen(corners, strel_diamond(2))),先去除小簇角点,但精准度不如基于距离的筛选。

内容的提问来源于stack exchange,提问作者F612

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 21:15:34