Use regionprops in a parent-children defect selction

4 ビュー (過去 30 日間)
Sean Dobson
Sean Dobson 2022 年 8 月 12 日
コメント済み: Image Analyst 2022 年 8 月 18 日
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};
plot(boundary(:,2),...
boundary(:,1),'g','LineWidth',2);
end
boundary = B{k};
stats = regionprops(boundary,'Area','Centroid','MajorAxisLength');
plot(boundary(:,2),...
boundary(:,1),'r','LineWidth',2);
end
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!

回答 (1 件)

Image Analyst
Image Analyst 2022 年 8 月 12 日
The foreground is the white part. So it's finding boundaries of the whole gigantic white area. I suggest you invert BW.
  2 件のコメント
Image Analyst
Image Analyst 2022 年 8 月 18 日
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.

サインインしてコメントする。

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by