Filter löschen
Filter löschen

Why doesn't bwconncomp detect each connected component as expected?

4 Ansichten (letzte 30 Tage)
Loren99
Loren99 am 6 Jun. 2022
Kommentiert: Image Analyst am 6 Jun. 2022
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 Kommentare
Walter Roberson
Walter Roberson am 6 Jun. 2022
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
Loren99 am 6 Jun. 2022
@Walter Roberson I have uploaded the zip file containing the main code 'codice_gvd' and other folders that are the functions and class functions needed to run the main code

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 6 Jun. 2022
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 Kommentare
Loren99
Loren99 am 6 Jun. 2022
@Image Analyst exactly! I would like to obtain the skiz (voronoi diagram) around these several irregularly shaped blobs. I have tried several algorithms: with the algorithm used here https://it.mathworks.com/matlabcentral/answers/1734135-how-to-eliminate-some-useless-lines-in-an-image there is the problem that even if I obtain the lines around the irregular shapes, I do not know how to do a pruning to remove the useless lines (the ones that are directly attached to the shapes). So I have tried another algorithm (the one that I have posted here and in the zip file) using bwconncomp, thinking that in this way creating connected components, maybe the in-built function voronoi does not generate that useless lines. Instead what happens is that bwconncomp generates the centroids of the irregular shapes and the voronoi diagram is created around these points, not around the shapes. I hope this is clear now, sorry

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Voronoi Diagram finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by