# Sampling nodes equally to cover all the environment

2 ビュー (過去 30 日間)
mohammed alany 2019 年 7 月 28 日
コメント済み: mohammed alany 2019 年 7 月 30 日
if i have this binary image, and i would like to distributed nodes in
the white area, which is the best way can distributed nodes to cover all the environments equally?
##### 4 件のコメント表示 3 件の古いコメント非表示 3 件の古いコメント
mohammed alany 2019 年 7 月 28 日
i am new in matlab
i perform this, how i can use kmeans now please?
BW = im2bw(map)
[y, x] = find(map)
c = [x, y]

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

### 採用された回答

Walter Roberson 2019 年 7 月 30 日
NC = 50;
BW = im2bw(map);
[y, x] = find(BW);
c = [x, y];
initpos = c(randperm(size(c,1),NC),:);
[idx,cents] = kmeans(c, NC, 'maxiter', 500, 'start', initpos);
ddd = squareform(pdist(cents));
ddd(1:(NC+1):end) = inf;
image(BW);
colormap(gray(2));
N = string(1 : NC);
hold on
scatter(cents(:,1), cents(:,2));
text(cents(:,1), cents(:,2), N);
hold off
You might notice some points at the bottom of the image. That white stripe along the bottom is part of the original image, and so distributing equally in the white portion requires placing some points in that white stripe.
##### 1 件のコメント表示 なし非表示 なし
mohammed alany 2019 年 7 月 30 日
Many thanks, all the time you are giving me the best solutions

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

### カテゴリ

Find more on C4ISR in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by