Use regionprops in a parent-children defect selction

3 views (last 30 days)
Hello! I am trying to analyze a binary image with defects - image below.
I want to use regionprops to get info on the defects (in black), but want to eliminate measurement error and not measure the incomplete defects at the edge of the image. I did this using the following:
%% Establish Boundaries
[B,L,N,A] = bwboundaries(BW);
figure(1); imshow(BW); hold on;
%% Loop through pores in boundaries
% Boundary k is the parent of a hole if the k-th column
% of the adjacency matrix A contains a non-zero element
for k = 1:N
boundary = B{k};
% Loop through the children of boundary k
for l = find(A(:,k))'
boundary = B{l};
boundary = B{k};
stats = regionprops(boundary,'Area','Centroid','MajorAxisLength');
This code returns the following with the edge defects outlined in red and the defects of interest in green. I need the area in pixel count of the red boundary, which is why it needs to be there.
However, when using regionprops, it seems to count the number of defects but doesn't provide any information on the green defects of interest. What am I doing wrong? Does the image need to be inverted? I tried putting regionprops in the for loop and still didn't get anything. Any guidance would be much appreciated. Thanks!

Answers (1)

Image Analyst
Image Analyst on 12 Aug 2022
The foreground is the white part. So it's finding boundaries of the whole gigantic white area. I suggest you invert BW.
Image Analyst
Image Analyst on 18 Aug 2022
Just eliminate partial defects on the border with imclearborder.
mask = imclearborder(mask == 0);
% Plot the borders of all the blobs in the overlay above the original grayscale image
% using the coordinates returned by bwboundaries().
imshow(originalImage); % Optional : show the original image again. Or you can leave the binary image showing if you want.
visboundaries(mask, 'Color', 'g')
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!