【问题标题】:Compute binary line thickness in normal direction计算法线方向的二进制线粗
【发布时间】:2019-11-15 04:37:47
【问题描述】:

我想请你帮忙定义线条粗细。我有二元曲线。我需要找出曲线骨架的每个点在法线方向上到线边缘的距离。所以,我首先计算了二元曲线的骨架。因此,对于骨架的每个像素,我计算了法线。图中描述了这种情况,显示了骨架和来自每个像素的法线向量图。在这一点上,我不知道如何计算每个骨架像素在法线方向上到曲线边缘的距离。实际上,我需要计算从骨架像素到法线方向的线边缘的像素数(逻辑 1)。这意味着我需要获取向量,其中包含每个骨架点的距离。我要提前感谢您的帮助。

用法线生成骨架的代码:

clc;clear all;close all
i=rgb2gray(imread('Bin_Lines.bmp'));

BW=bwskel(logical(i));

% BW = image sceleton

Orientations = skeletonOrientation(BW,5); %5x5 box
Onormal = Orientations+90; %easier to view normals
Onr = sind(Onormal); %vv
Onc = cosd(Onormal); %uu
[r,c] = find(BW);    %row/cols
idx = find(BW);      %Linear indices into Onr/Onc

figure()
imshow(BW,[]);
%Plotting normals of binary skeleton
hold on
quiver(c,r,-Onc(idx),Onr(idx));

这是我存储源代码和二进制行图像的链接:

https://www.dropbox.com/sh/j84ep3k1604hsza/AABm92TUBX6yIp29Gc0v_PHHa?dl=0

【问题讨论】:

    标签: matlab image-processing computer-vision image-segmentation edge-detection


    【解决方案1】:

    您可以使用distance transform 计算每个内部像素到边界的距离。 Matlab 有 bwdist 为您执行此操作。
    然后就可以提取骨架像素的信息了。

    img = rgb2gray(imread('Bin_Lines.bmp'));  
    bw = bwskel(img > 128);
    dst = bwdist(img <= 128);  % need opposite contrast
    distance_of_skel_pixels_to_boundary = dst(bw)
    

    dst 的距离看起来像:

    【讨论】:

    • 亲爱的 Shai, 非常感谢。它看起来对我来说非常好和有用。
    • @jendula11 很高兴我能帮上忙。如果此答案对您有用,请考虑通过单击旁边的“v”图标“接受”它
    猜你喜欢
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    相关资源
    最近更新 更多