How to extract edge coordinates

31 vues (au cours des 30 derniers jours)
文辉 沈
文辉 沈 le 24 Avr 2022
Commenté : 文辉 沈 le 26 Avr 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;
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

Réponses (1)

Image Analyst
Image Analyst le 24 Avr 2022
Modifié(e) : Image Analyst le 24 Avr 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.
  3 commentaires
文辉 沈
文辉 沈 le 26 Avr 2022
First: During the modification process, 00001 can meet the requirements, but the 00002 image skeleton process has problems, which cannot show his skeleton,how do I solve this situation?
Second, after the crack display, how can I determine the coordinates of the white area at the border point, test .jpg. My idea is to extract the pixel coordinates on the edge, which will appear 0 (cracks)and 1, but the running results show that it is all 1. Why is this?
My program is in data_processing.m,Among them,%2 is the code that runs wrong after, is the matrix of the extraction border pixel coordinates mentioned above
文辉 沈
文辉 沈 le 26 Avr 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

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by