How to extract edge coordinates
18 views (last 30 days)
Show older comments

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;
filename_new=strcat(filename_old(1:end-4),"_processed",".jpg");
I=imread(fullfile(pathname_old,filename_old));
core = fspecial('gaussian',[9,9],1);
bw = imfilter(I,core);
sh = graythresh(bw);
img = im2bw(bw,sh);
img1 = ~img;
bw1=bwmorph(img1,'dilate',1);
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);
pathfilename_new=fullfile(pathname_new,filename_new);
imwrite(bw1,pathfilename_new);
end
0 Comments
Answers (1)
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!