jendula11
jendula11

Reputation: 11

Compute binary line thickness in normal direction

I would like to kindly ask you for the help with the definition of the line thickness. I have the binary curve. I need to find out a distance of each point of the curve skeleton to line edge in the direction of the normal. So, I firstly computed skeleton of the binary curve. Consequently, for each pixel of the skeleton I computed normal. This situation is depicted on the figure, showing the skeleton and a map of normal vectors from each pixel. In this point, I do not know how to compute the distance for each skeleton pixel to curve edge in the normal direction. Practically, I need to count number of the pixels (logical 1) from the skeleton pixels to the line edge in the normal direction. It means I need to obtain the vector, containing distance for each skeleton point. I would like to thank you in advance for your help.

Code for generating skeleton with normals:

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));

Here is the link where I store source codes and binary line image:

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

Upvotes: 1

Views: 174

Answers (1)

Shai
Shai

Reputation: 114806

You can use distance transform to compute the distance of each interior pixel to the boundary. Matlab has bwdist to do that for you.
Then you can extract the information for the skeleton pixels.

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)

The distance dst looks like:
enter image description here

Upvotes: 5

Related Questions