计算法线方向上的二进制线宽

1 matlab image-processing computer-vision edge-detection image-segmentation

我想请您提供有关线宽定义的帮助。我有二进制曲线。我需要找出曲线骨架的每个点到法线方向上的线边缘的距离。因此,我首先计算了二进制曲线的骨架。因此,对于骨骼的每个像素,我都计算了法线。图中描绘了这种情况,显示了每个像素的骨架和法线向量图。在这一点上,我不知道如何计算每个骨架像素在法线方向上弯曲边缘的距离。实际上,我需要计算从骨架像素到法线方向上线条边缘的像素数量(逻辑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));
Run Code Online (Sandbox Code Playgroud)

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

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

Sha*_*hai 5

您可以使用距离变换来计算每个内部像素到边界的距离。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)
Run Code Online (Sandbox Code Playgroud)

距离dst看起来像:
在此处输入图片说明