How to extract edge coordinates

28 views (last 30 days)
文辉 沈
文辉 沈 on 24 Apr 2022
Commented: 文辉 沈 on 26 Apr 2022
After I extract the edge of the binarized image, the output is an array of 227*227, and each row and each column are all 1. How can I achieve the effect in the image: display the length, width and angle of the crack
The intermediate code is as follows:
for i = 1:n
filename_old = filelList(i).name;
core = fspecial('gaussian',[9,9],1);
bw = imfilter(I,core);
sh = graythresh(bw);
img = im2bw(bw,sh);
img1 = ~img;
dim = size(bw1);
col1 = 4;
row1 = find(bw1(:,col1), 1);
row2 = 12;
col2 = find(bw1(row2,:), 1);
boundary1 = bwtraceboundary(bw1, [row1, col1], 'N',8,227);
boundary2 = bwtraceboundary(bw1, [row2, col2], 'E',8,227,'counter');
ab1 = polyfit(boundary1(:,2), boundary1(:,1), 1);
ab2 = polyfit(boundary2(:,2), boundary2(:,1), 1);

Answers (1)

Image Analyst
Image Analyst on 24 Apr 2022
Edited: Image Analyst on 24 Apr 2022
You can use plot() to plot the green boundary.
You can use bwareaopen() to extract blobs of only a specified size or larger.
You can use bwareafilt() if you want to extract the largest blob only.
You can use text() to place the blue text on the image.
You can use line() or plot() to plot the blue lines.
You can do this to find the average angle (but make sure you don't have that white frame around the edge of the image like you do in your attached image)
[y, x] = find(binaryImage);
coefficients = polyfit(x, y, 1);
slope = coefficients(1);
angle = atand(slope)
If you need the average width, compute the Euclidean distance transform and multiply it by the skeleton then get the mean of the non-zero values. See attached demo.
If you need more help, attach an original RGB image without the annotations.
文辉 沈
文辉 沈 on 26 Apr 2022
Now I can mark up, the picture is linked, but I haven't been able to find a way to get the coordinates of the crack boundary points

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by