Why doesn't bwconncomp detect each connected component as expected?
이전 댓글 표시
Hi everyone!
I have the following binary image M

I have a problem with bwconncomp. My aim is to generate Voronoi diagrams using as input not single points but blobs/connected components. However the command bwconncomp fails to detect each connected component as expected; as you can see from the following figure, it seems to calculate the centroid of every cluster of pixels, which is not what I want because I would obtain the voronoi diagram around the yellow shapes of the first figure, not around a single centroid point. How can I solve this? I attach an extract of my code and a zip file containing the functions and the main code called codice_gvd.m. Thanks in advance

%% Pose
% Initial Pose
xs = 70; ys = 76; % valori iniziali 55 e 33
% Goal Pose
xg = 50; yg = 50; % valori iniziali 50 e 50
% Pose Matrix
pose = zeros(sz(1),sz(2));
pose(ys,xs) = 1;
pose(yg,xg) = 1;
%% Voronoi Road Map
figure('color','k');
hold on;
set(gcf, 'InvertHardCopy', 'off');
CC = bwconncomp(M);
p = CC.PixelIdxList;
m = zeros(length(p), 2);
for ii = 1:length(p)
[r, c] = ind2sub(size(M), p{ii});
m(ii,:) = [mean(c), mean(r)];
end
voronoi(m(:,1), m(:,2));
title({'Voronoi Road Map';'* - Represents Starting and Goal Position '},'color','w');
spy(pose,'*r')
댓글 수: 2
Walter Roberson
2022년 6월 6일
CC = bwconncomp(hit);
we need hit for testing purposes. Also if hit is derived from something else it would help to see the logic chain
Loren99
2022년 6월 6일
답변 (1개)
Image Analyst
2022년 6월 6일
0 개 추천
Your binary image, hit, is a 1-D vector, not really an image. So not sure why you seem to be expecting that it's a 2-D image.
댓글 수: 4
Loren99
2022년 6월 6일
Image Analyst
2022년 6월 6일
What do you want? So let's say that in general you have a binary image with several irregularly shaped blobs in it. You can get their boundaries, centroids, areas, pixel locations within the blob, etc. In other words, you can measure a whole bunch of things about those blobs. What would you like to measure? The skiz?
Loren99
2022년 6월 6일
Image Analyst
2022년 6월 6일
See Steve's blog where he computes the skiz:
카테고리
도움말 센터 및 File Exchange에서 Region and Image Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!